CSV File in a FOR Loop returns "url must be a string" error - csv

I am trying to craft a Robot Framework test that will iterate through different sites and login to them. There are two different kinds of login procedures and I've written up login steps for each. Those are stored as keywords. But I'm running in the URLs through a CSV file. The file contains the URL, and the "login_type", A or B. I want to iterate this through a FOR loop, to where I just have to call the file at runtime and the CSV file will take care of the rest.
But I am getting an error message that says "'url' must be a string." I'm not sure if my problem is the CSV file or my loop structure is wrong. Here is my code:
*** Settings ***
Documentation Store URLs in CSV and identify login type
Library Zoomba.GUILibrary
Library Process
Library CSVLibrary
Library Collections
Resource ../resource.robot
Suite Teardown Close All Browsers
*** Variables ***
${browser} chrome
${url} https://example1.edu
${CSV_FILE} C:/CSV.csv
*** Test Cases ***
Example Test
${urls} Read Csv File To List ${CSV_FILE}
FOR ${url} IN #{urls}
Open Browser ${url} ${browser}
${login_type} Get CSV Data ${url} login_type
Run Keyword If '${login_type}' == 'TYPE A' A Login <--stored keyword
Run Keyword If '${login_type}' == 'TYPE B' B Login <--stored keyword
Log To Console ${url} verified.
END
Here is the CSV file I'm using.
What am I doing wrong here? Can anybody answer this?

You should try to debug your test by logging the values. For example, after ${urls} Read Csv File To List ${CSV_FILE} you could have a Log Many ${urls}.
Then check why ${url} is not really a string. You could also try to force it to be a string by quoting, '${url}' or "${url}".

Related

CSV file read issue in firebase functions

I am trying to read a csv file in a firebase function so that I can process the file and do the rest operations using the data.
import * as csv from "csvtojson";
const csvFilePath = "<gdrive shared link>"
try{
console.log("First Method...")
csv()
.fromFile(csvFilePath)
.then((jsonObj: any)=>{
console.log("jsonObj....",JSON.stringify(jsonObj));
})
console.log("Second Method...")
const jsonArray=await csv().fromFile(csvFilePath);
console.log("jsonArray...", JSON.stringify(jsonArray))
}
catch(e){
console.log("error",JSON.stringify(e))
}
The above mentioned are the 2 methods I have tried for reading the csv but both shows the firebase error
'Error: File does not exist. Check to make sure the file path to your csv is correct.'
In case of 'csvFilePath' I have tried 2 methods
Just added the csv file in same folder of the function and added the code like
const csvFilePath = "./student.csv"
Added the same file to google drive and changed the access permissions to anyone with the link can read and edit and given the path to same
const csvFilePath = "<gdrive shared link>"
Both shows the same error. In case of google drive I don't want to use any sort of google credential because I was intented to read a simple csv file in firebase function.
I will start by proposing that you convert your csv to json locally or without the function and see if it works. This is because I see you are using ES6 imports which might be causing an issue since all the documentation uses require. You can also try CSV Parse or some solutions provided in this question as an alternative, trying them without the function to check if it actually works and discard it. Actually, you can upload the JSON once you have converted it from the csv, but that depends on what you are trying to do.
I think the best way to achieve this, is following the approach given in this question, that first uploads the file into cloud storage and using onFinalize() to trigger the conversion.
Also, will address these three questions that went through similar issues with the path. They were able to fix it by adding __dirname. Each one has some extra useful information.
Context for "relative paths" seems to change to the calling module if a module is imported
The csvtojson converter ignores my file name and just puts undefined
How to avoid the error which throws a csvtojson

Problem downloading package from git actions, results in mangled URL

In our git actions output for testing our custom R package (hosted on github), we're experiencing an error during execution:
Error in utils::download.file(url, path, method = method, quiet = quiet, :
cannot open URL 'https://api.github.com/repos/***/CirceR/contents/DESCRIPTION?ref=HEAD'
Calls: saveRDS ... github_DESCRIPTION -> download -> base_download -> base_download_headers
Execution halted
Error: Process completed with exit code 1.
The main repo is here: https://github.com/OHDSI/CohortGenerator
The github actions report is here: https://github.com/OHDSI/CohortGenerator/runs/3294257207?check_suite_focus=true
The referenced package CirceR is found here: https://github.com/ohdsi/circer
Our main question is: is it normal for the requested URL for the DESCRITPION file to be masked with the *** as in: cannot open URL 'https://api.github.com/repos/***/CirceR/contents/DESCRIPTION?ref=HEAD'
If we change the *** to the actual organization OHDSI for this URL the request works, so is it possible the URL is being mangled?
We've tested loading each individual package locally and this error doesn't occur, so we think it's localized to github actions.
I believe the output is trying to shorten the string so you can see how it starts, and how it ends, but not the middle...for readability purposes. My issue was I wanted the entire contents of the string (other errors in 'shorter' repository names gives the full URL). So, I believe this truncation is by design.
To solve the underlying issue, I had to specify a GIT_PAT to use to invoke the API and that cleared out the error I was getting.

Zabbix web scenario debug

To figure out the problems in web scenario I need to check values of variables (macros) in some steps. I expect view in Web interface...
Currently log is accessible only from system, but there is an ugly workaround to view variables:
Add step to not existing URL with variable in path, for example:
https://{HOST.DNS}/{some_variable}/{some_other_variable}
server probably return error page, but you can set is as expected in Required status codes
set Required string to an not existing on error page, for example "not existing string"
then in details of web scenario you can see status:
Error: required pattern "not existing string" was not found on https://some.dns/some_variable_value/some_other_variable_value

Download a file from Google Drive using google-api-ruby-client

I try to download files from a directory on Google Disk.
The code, mostly copied from official quickstart guide, works fine:
# ... code from official quickstart tutorial...
# Initialize the API
service = Google::Apis::DriveV3::DriveService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
# now the real deal
response = service.list_files(q: "'0ByJUN4GMe_2jODVJVVpmRE1VTDg' in parents and trashed != true",
page_size: 100,
fields: 'nextPageToken, files(id, name)')
puts 'Files:'
puts 'No files found' if response.files.empty?
response.files.each do |file|
puts "#{file.name} (#{file.id})"
# content = service.get_file(file.id, download_dest: StringIO.new)
end
The output looks fine:
Files:
k.h264 (0B4D93ILRdf51Sk40UzBoYmZKMTQ)
output_file.h264 (0B4D93ILRdf51V1RGUDFIWFQ5cG8)
test.mp4 (0B4D93ILRdf51dWpoZWdBV3l4WjQ)
test2.mp4 (0B4D93ILRdf51ZmN4ZGlwZjBvR2M)
test3.mp4 (0B4D93ILRdf51ZXo0WnVfdVBjTlk)
12.mp4 (0ByJUN4GMe_2jRzEwS1FWTnVkX00)
01.mp4 (0ByJUN4GMe_2jSlRWVEw4a1gxa2s)
01.mp4 (0ByJUN4GMe_2jOFpPMW9YNjJuY2M)
But once I uncomment content = service.get_file(file.id, download_dest: StringIO.new), I get a lot of errors:
Files:
k.h264 (0B4D93ILRdf51Sk40UzBoYmZKMTQ)
/Users/mvasin/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/google-api-client-0.9.15/lib/google/apis/core/http_command.rb:211:in `check_status': Invalid request (Google::Apis::ClientError)
[...lots of other 'from' stuff...]
from /Users/mvasin/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/google-api-client-0.9.15/generated/google/apis/drive_v3/service.rb:772:in `get_file'
from quickstart.rb:56:in `block in <main>'
from quickstart.rb:54:in `each'
from quickstart.rb:54:in `<main>'
But that's the way it should work according to ruby section in "download files" official tutorial.
I also tried content = service.get_file(file.id, download_dest: "/tmp/#{file.name}"), but it failed with the same set of errors.
UPDATE: Here are my findings. If you start with Google Drive API Ruby quick start tutorial, and want make it download something,
1) change scope to not just let your script read meatadata, but read files contents as well:
SCOPE = Google::Apis::DriveV3::AUTH_DRIVE_METADATA_READONLY
to at least
SCOPE = Google::Apis::DriveV3::AUTH_DRIVE_READONLY
2) Filter out google docs files, because you can't download them this way, you have to convert them. To filer them:
2.1) Add mime_type to fileds set:
response = service.list_files(page_size: 10, fields: 'nextPageToken, files(id, name, mime_type)')
2.2) and in the final loop where you print files' ids and names, put something like
service.get_file(file.id, download_dest: "/your/path/#{file.name}") unless file.mime_type.include? "application/vnd.google-apps"
From the error that you got, it says that your request is invalid. So make sure that your request there are correct. Here is the documentation on how to download files using Ruby(just click the Ruby on the example to view the ruby code.)
Take NOTE: Downloading the file requires the user to have at least
read access. Additionally, your app must be authorized with a
scope
that allows reading of file content.
For more information, check these threads:
How to download file from google drive api
A Ruby library to read/write files

Perl HTML file upload issue. File has zero size

I have a perl CGI script, that works, to upload a file from a PC to a Linux server.
It works exactly as intended when I write the call to the CGI in my own HTML form and then execute, but when I put the same call into an existing application, the file is created on the server, but does not get the data, it is size zero.
I have compared environment variables (those I can extract from %ENV) and nothing there looks like a cause. I actually tried changing several of the ENV in my own HTML script, to the values the existing application was using, and this did not reveal the problem.
Nothing in the log gives me a clue, the upload operation thinks it was successful.
The user is the same for both tests. If permissions were an issue, then the file would not even be created on the server.
Results are the same in IE as in Chrome (works from my own HTML script, not from within the application).
What specific set up should I be looking at, to compare?
This is the upload code:
if (open(UPLOADFILE, ">$upload_dir/$fname")) {
binmode UPLOADFILE;
while (<$from_fh>) {
print UPLOADFILE;
}
close UPLOADFILE;
$out_msg = "Done with Upload: upload_dir=$upload_dir fname=$fname";
}
else {
$out_msg = "ERROR opening for upload: upload_dir=$upload_dir filename=$filename";
}
I did verify that
It does NOT enter the while loop, when running from inside the application.
It does enter the while loop, when called from my own HTML script.
The value of $from_fh is the same for both runs.
All values, used in the below block, are exactly the same for both runs.
You could check the error result of your open?
my $err;
open(my $uploadfile, ">", "$upload_dir/$fname") or $err = $!;
if (!$uploadfile) {
my $out_msg = "ERROR opening for upload: upload_dir=$upload_dir filename=$filename: $err";
}
else {
### Stuff
...;
}
My guess, based on the fact you are embedding it in another application, is that all the input has been read already by some functionality that is part of the other application. For example, if I tried to use this program as part of a CGI script, and I had used the param() function from CGI.pm, then the entire file upload would have been read already. So if my own code tried to read the file again, it would receive zero data, because the data would have been ready already.