Someone test URLDownloadToFile_ for me? Strange results

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Someone test URLDownloadToFile_ for me? Strange results

Post by Fangbeast »

Could someone please test this for me? In my OMDBAPI program, I have been getting back all information and poster for the searched file but on some queries, the image doesn't come back and I am getting a strange status message of -2146697208.

The image does exist on the IMDB page so I know it's there.

Cobbled together the code below to show that I am not going mad.

Code: Select all

#FileNotFound       = -1
#FileIsDirectory    = -2

IllegalCharacters.s = "\/:*?" + Chr(34) + "<>|"
PictureDirectory.s  = "D:\Itest\"
PictureFilename.s   = #Empty$
PosterFile.s        = "http://ia.media-imdb.com/images/M/MV5BMTM5NjU5MzMzMF5BMl5BanBnXkFtZTcwMTEzODYyMQ@@._V1_SX300.jpg"
NetworkUpStatus.i   = InitNetwork()

If NetworkUpStatus.i <> #False
  StringData.s        = URLEncoder(PosterFile.s)
  ExtensionPart.s     = GetExtensionPart(StringData.s)
  PictureFilename.s   =  "SmegittyFlapDoodle." + ExtensionPart.s
  For KillBadChars.i  = 1 To Len(IllegalCharacters.s)
    PictureFilename.s  = ReplaceString(PictureFilename.s, Mid(IllegalCharacters.s, KillBadChars.i, 1), " ", #PB_String_NoCase)
  Next KillBadChars.i
  ReplaceString(PictureFilename.s, "  ", " ", #PB_String_NoCase)
  PictureDownloadStatus.i = URLDownloadToFile_(0, StringData.s, PictureDirectory.s + PictureFilename.s, 0, 0)
  If PictureDownloadStatus.i = #S_OK
    PictureFoundStatus.i = FileSize(PictureDirectory.s +  PictureFilename.s)
    If PictureFoundStatus.i <> #FileNotFound And PictureFoundStatus.i <> #FileIsDirectory
    Else
      Debug  "Picture file wasn't saved, not found or is a directory::: Filesize = " + Str(FileSize(PictureDirectory.s +  PictureFilename.s))
    EndIf
  Else
    Debug  "Could not fetch::: " + StringData.s  + " :::  Status ::: " + Str(PictureDownloadStatus.i)
  EndIf
Else
  Debug "Could not start the network functions. Status code is :::  " + Str(NetworkUpStatus.i)
EndIf
End
Amateur Radio, D-STAR/VK3HAF
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Someone test URLDownloadToFile_ for me? Strange results

Post by BarryG »

Fangbeast wrote:The image does exist on the IMDB page so I know it's there.

Code: Select all

PosterFile.s = "http://ia.media-imdb.com/images/M/MV5BMTM5NjU5MzMzMF5BMl5BanBnXkFtZTcwMTEzODYyMQ@@._V1_SX300.jpg"
Are you sure the image exists? When I copy and paste that URL into Firefox I get a "403 Error" for it, and no image is shown.

[Edit] It needs to be "https" to work:

Image
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Someone test URLDownloadToFile_ for me? Strange results

Post by Fangbeast »

BarryG wrote:
Fangbeast wrote:The image does exist on the IMDB page so I know it's there.

Code: Select all

PosterFile.s = "http://ia.media-imdb.com/images/M/MV5BMTM5NjU5MzMzMF5BMl5BanBnXkFtZTcwMTEzODYyMQ@@._V1_SX300.jpg"
Are you sure the image exists? When I copy and paste that URL into Firefox I get a "403 Error" for it, and no image is shown.

[Edit] It needs to be "https" to work:

Image
Yes, the image exists. Works fine in my browser without https, amazon references the image as-is, not secure link. I have also tried the native Purebasic function and it returns the same thing.

Works in browser, but not in pb download functions.

But only some images and not others. The ones that fail in pb all work in the browser. mystified.
Amateur Radio, D-STAR/VK3HAF
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Someone test URLDownloadToFile_ for me? Strange results

Post by Fangbeast »

Okay, that's weird. The image as provided downloads in the browser with HTTP.

If I replace that with HTTPS as you suggested, it works with the PB function.

Still does not explain why some images work with HTTP and this one *ONLY* works with HTTPS
Amateur Radio, D-STAR/VK3HAF
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 340
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: Someone test URLDownloadToFile_ for me? Strange results

Post by ar-s »

The http do not work for me. https do.
Try to clean up your navigator cache and try again to access with http.
Today modern browsers like firefox, chrome etc... prefer https.

A simple http://ia.media-imdb.com/ returns a 403 ERROR (that is an acces denied) while https://ia.media-imdb.com/ returns an Error 400 Bad Request (that is normal for that website)
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Someone test URLDownloadToFile_ for me? Strange results

Post by Fangbeast »

ar-s wrote:The http do not work for me. https do.
Try to clean up your navigator cache and try again to access with http.
Today modern browsers like firefox, chrome etc... prefer https.

A simple http://ia.media-imdb.com/ returns a 403 ERROR (that is an acces denied) while https://ia.media-imdb.com/ returns an Error 400 Bad Request (that is normal for that website)
HTTP works fine in my browser for the images, not https.

Maybe Firefox is doing something here that works for it while your browsers don't like it? Don't know.

I'll try changing all PB URL download requests to https and see if it works for all of them.
Amateur Radio, D-STAR/VK3HAF
infratec
Always Here
Always Here
Posts: 6874
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Someone test URLDownloadToFile_ for me? Strange results

Post by infratec »

Maybe the hoster sends a 301 for redirection to hhtps and the browser follows this redirection.
And maybe this api call does not follow a redirection.

Why you don't use the PB functions to download the file?
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Someone test URLDownloadToFile_ for me? Strange results

Post by Fangbeast »

Maybe the hoster sends a 301 for redirection to hhtps and the browser follows this redirection.
Hmm, never thought of that. Never occurred to me:):)
Why you don't use the PB functions to download the file?
Even though the pb command is supposed to be a wrapper for the API command, it has failed me many times before where the API version worked. Just got used to leaving it there now as it works all the time (Except for the redirection of course (HEHE))
Amateur Radio, D-STAR/VK3HAF
Post Reply