Issues downloading a .list file

Hello, I’m new here.

I’m a test engineer doing some tests with Robot Framework and Browser library. I saw that there is a keyword for downloading files directly from a URL (Download) but I’m having some trouble getting the file to be downloaded. The link to the file is https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list. It’s a direct link and should be easy to download using the KW, but with this simple code I cannot perform it:

Prueba
    [Documentation]    a
    ${leap seconds url} =    Get Regexp Matches    ${LEAP SECONDS TXT}    https.+
    Download    ${leap seconds url}[0]

I don’t know what I’m doing wrong but this KW always returns this error and I don’t know what I’m doing wrong. Note: the posted link is inside the ${LEAP SECONDS TXT} variable defined at the top of the file.

Error: page.evaluate: TypeError: Failed to fetch
    at eval (eval at evaluate (:197:30), <anonymous>:2:12)
    at UtilityScript.evaluate (<anonymous>:199:17)
    at UtilityScript.<anonymous> (<anonymous>:1:44)

Thanks in advance.

I forgot to mention that there is already a browser and context opened with allowDownloads to True.

Hi Javier,

Welcome to the community.

First thing to check is what the contents of ${leap seconds url} is?

  • is it a string?
  • is it a list?
  • is it a list of tuples?

As Get Regexp Matches has various outputs.

Next it might be worth logging ${leap seconds url}[0] to make sure it’s what you expected

 Log    ${leap seconds url}[0]

Hopefully it’s not something silly like “h” or “('https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list', 'something')” (a tuple)

If everything is as expected, I also noticed Download expects at least 2 arguments and you only have one, the url (source), but not saveAs (destination), so maybe that’s your issue?

Dave.

It’s a string which I parse using a regex. I tested it in regex101 and no issues parsing this string so the link is properly obtained.

If I’m correctly the saveAs argument is optional. If the argument is empty, a random GUID will be used to name the file. Maybe am I wrong?

Thanks Dave.

Hi Javier,

Ah yes you are correct about the GUID filename, I missed that (I’ve never used this keyword myself)

Without the full error in the robot logs it’s a bit hard to know what the problem is, based on the snippet of the error you showed you have a type error, this does not look like a robot error but rather a playwright error.

So the only thing I can think of that would cause a type error is an argument that’s not the type Browser Library expected.

So these are the only scenario’s I can think of that would cause your error:

  • If ${leap seconds url} is a string then ${leap seconds url}[0] will just return the first character of the string (h?) which might be auto-converted into a byte or char?, that could cause a type error

  • ${leap seconds url} is a list of tuples, then ${leap seconds url}[0] would return the first tuple and that would cause a type error

Dave.

If I understand somewhat correctly, you are trying to grab an URL from a webpage (the block of text seen in the link you provided, which is what is seen when navigating to https://hpiers.obspm.fr/iers/bul/bulc/ntp/leap-seconds.list) and assuming you have done this successfully, you are grabbing the first instance of the match with the pattern you have provided from the stored data in the variable.

If I take the text and run that keyword with that pattern, I get:

As you can see, it holds a single right parenthesis at the end and that you may just need to adjust your pattern slightly?

https.+.dat

You will then get returned just a single URL, as there is only one “. dat” on that page, just to note you cant add a single parenthesis and escape in the pattern, as it would seem with robot framework doesnt like it which is why ive added the .dat to the pattern so it doesnt drag back the right parenthesis, but escaping that will return an error error: unbalanced parenthesis for visibility, whereas you could with regex101

As @damies13 touched on, seeing the full log for where it was thrown would be beneficial, but if, let’s say, what you have stored in ${LEAP SECONDS TXT} is valid and was succesfuly upto that point then possibly the reason why its falling over is that the URL passed to the download keyword is thrown as a result of the URL holding a single right parenthesis as the URL is invalid

image

I could be wrong but just another angle :slight_smile:

Thanks

1 Like

Thankks everyone for contributing.

1 Like