Image inaccessible from python script but accessible in browser - python-3.x

I was trying to automatically download some traffic camera photos to play around with some image object recognition scripts and I have found that some links to them will throw a 403: Forbidden error when I try to download them from Python, and yet I can access them in a browser. One such image is at this link: https://www.svz-bw.de/kamera/ftpdata/KA101/KA101_gross.jpg
This code:
urllib.request.urlretrieve("https://www.svz-bw.de/kamera/ftpdata/KA101/KA101_gross.jpg", "traffic.jpg")
Returns a 403 error for me. What gives? I can understand that perhaps these organizations are not keen on having people bog down their servers with automatic downloads and perhaps there are some GDPR-related constraints, but I am actually more curious about how they are able to detect that the request is coming from a script and not from normal use

Related

SVG image Download URL Link is not working in FFImageLoading in Xamarin Forms [duplicate]

What I want to do is to create a direct link URL to a mp3 file which is located on my Google Drive and use it on Audio object of HTML5, but I get 403 error.
I know that when one tries to create a link of a file located on Google Drive, it creates not a direct URL to the file but a URL for viewing the file through a viewer such as
https://drive.google.com/file/d/<file ID>/view?usp=sharing
I googled to find it is possible to rewrite it into a direct link URL like this:
https://drive.google.com/uc?id=<file ID>
I set this URL in the src property of my audio element. However, when I try play() method, the following error is thrown:
GET https://drive.google.com/uc?id=<file ID> 403
myProject.html:1 Uncaught (in promise) DOMException: Failed to load because no supported source was found.
So I tried to access to the URL https://drive.google.com/uc?id=<file ID> from my browser.
Then, I got this:
403. That’s an error.
We're sorry, but you do not have access to this page. That’s all we know.
I tried many times so it is not likely that I'm mis-pasting the <file ID>.
What should I do to create a valid direct link URL of the file?
I would appreciate for any information.
Progress
I got what was wrong.
The problem was that a file on Google Drive can be accessed only from the user who is authorized, which means only the owner of the Google account can access the file URL.
I tried to access it from Chrome Browser which is associated with the Google account, then, the error didn't occur.
However, I want to serve this file to all the people.
What should I do to give permission for access to other people?
You understand that Google drive is not a file hosting service right? This solution is not going to be very stable even if you do get it to work.
For it to work your going to need to set the file public so that everyone can access it. Then i would be willing to bet you will need an API key to do this in the long run.
Also remember that file id is not stable it can change in the future if for example you upload the file.
I solved this on my own. I right clicked the file, clicked Get link, and changed the authorization selection from Restricted into Anyone with the link. Then, the 403 error vanished for the access from anyone.

YouTube Data API v3 OAuth setup from Python

I am using Python to directly run a script of automatically replying user's comments.
I have a client secrets file after applying for a web-application. However, when I run for credentials, it first asks me to Please visit this URL to authorize this application and then when I clicked on it, it gives me this error:
Error 400: redirect_uri_mismatch The redirect URI in the request, urn:ietf:wg:oauth:2.0:oob, can only be used by a Client ID for native application. It is not allowed for the WEB client type. You can create a Client ID for native application at.
What application should I have applied for the OAuth in this case.
I know that this issue could be related to redirect URL. But because I am running this out of my script on my local computer, I am wondering what my URL should be.
You have to acknowledge that your issue above is precisely due to the redirect URI mismatch. The error response you got from the API is indicating you this.
To fix you issue, you'll have to have the same redirect URI set on your project within Google developers console and, at the same time, within your Python script.
If you indeed are running your application on your desktop (laptop) computer, then follow on the error message advice: within Google developers console, do set your project type to be of Desktop kind.

Why call of Google Slides API returns error?

I have essentially been using this code to load an image into Google Drive and then transferring that image over to Google Slides using Python and for some reason it stopped working today.
The code I based mine off of is located here:
http://wescpy.blogspot.com/2016/11/using-google-slides-api-with-python.html
However, today I reran it and am getting an error:
googleapiclient.errors.HttpError: https://slides.googleapis.com/v1/presentations/PRESENTATION_ID returned "Invalid requests[0].createImage: Access to the provided image was forbidden.">
I am wondering if anything have changed in Google API?
Are you getting the same error today 2020/3/6?
<HttpError 400 when requesting https://slides.googleapis.com/v1/presentations/6-7HI:batchUpdate?fields=&alt=json returned "Invalid requests[24].createImage: Access to the provided image was forbidden.">
The error happens every time I am trying to push any image stored in Google Slides using either createImage or replaceAllShapesWithImage.
Note that the URLs pointing at Google Drive content are related to Public content. Thus, the workaround above mentioned by #miladio is not useful at this time.
I ran into the same issue. You should check out this link, which describes changes to the Drive API: Upcoming changes to the Google Drive API and Google Picker API
The proposed solution here seems feasible, although I have not fully tested it myself: Google script replaceAllShapesWithImage with image from drive doesn"t work any more

Retrieve BLOGS_UPLOADED_IMAGES in java

I have some java code that retrieves blogs through the REST API's. I am not using the social business toolkit, but we have our own framework for that.
The application works perfectly on an on-premise connections environment and has worked on multiple versions.
However when switching to Connections Cloud, some parts stopped worked.
We get a 403 - Forbidden exception on 2 occasions:
Getting the details of a blog post: /blogs/[blog-id]/feed/entry/atom?entryid=[entry-id]
Getting images inside the blog post: /blogs/[blog-id]/resource/BLOGS_UPLOADED_IMAGES/[image file name]
I have fixed issue 1) by switching to the plublishing API: /blogs/[blog-id]/api/entries/[entry-id].
I cannot find a way to fix issue 2). I have also found 2 other image urls:
https://apps.ce.collabserv.com/blogs/[blog-id]/api/media/[file-name]
https://apps.ce.collabserv.com/blogs/[blog-id]/api/media/BLOGS_UPLOADED_IMAGES/[file-name].media
Both return:
<sp_0:error xmlns="http://incubator.apache.org/abdera" xmlns:sp_0="http://incubator.apache.org/abdera">
<code>404</code>
<message>Not Found</message>
</sp_0:error>
I want to authenticate by using Basic Authentication when possible. This does not appear to work with the given 403 urls.
My guess is that this the basic authentication header is not picked up. I have seen this before.
I used to fix this by first calling another URL that does support basic authentication and using the Ltpa cookies to authenticate the image url.
This also does not work: I do get LtpaTokens, but when I pass all the cookies to the URL, the image still does not work.
I prefer not to use OAuth of OAuth 2 at this moment. Is there any other way to fix this?
Anybody else managed to retrieve BLOGS_UPLOADED_IMAGES?
The issue is can also be reproduced in a browser.
Make sure you are not yet authenticated and the blog has posts with
images
Go to /blogs/[blog-id]/api/media
Authenticate using the popup in the browser The Atom feed now appears. This contains the images of your blog.
403 when opening:
/blogs/[blog-id]/resource/BLOGS_UPLOADED_IMAGES/[image]
404 xml when opening: /blogs/[blog-id]/api/media/* links

Images stopped showing using Smart Lencioni Image Resizer

I don't know what I did, but for some reason images stopped working. Some browsers show the image, but the majority don't. I'm using v1.4.1 of Lencioni Image Resizer
This image will not show:
http://www.norwegianfashion.no/wp-content/themes/norwegianfashion/image.php?width=280&height=&cropratio=2:1&image=http://www.norwegianfashion.no/wp-content/uploads/magazine/issue5/siri1_72dpi.jpg
But you can access the image here:
http://www.norwegianfashion.no/wp-content/uploads/magazine/issue5/siri1_72dpi.jpg
If I change & with &, I get the message Error: no image was specified.
http://www.norwegianfashion.no/wp-content/themes/norwegianfashion/image.php?width=280&height=&cropratio=2:1&image=http://www.norwegianfashion.no/wp-content/uploads/magazine/issue5/siri1_72dpi.jpg
Another place I'm using it, is here, and that works fine:
http://www.advicis.no/wp-content/themes/business1/image.php?width=150&height=&cropratio=1:1&image=http://www.advicis.no/wp-content/uploads/OD-puzzle-large.jpg
What could cause this?
Apparently your PHP script cannot access the url http://www.norwegianfashion.no/wp-content/uploads/magazine/issue5/siri1_72dpi.jpg.
I can, and you can, but the server on which the PHP script is running can't.
Perhaps the PHP server doesn't have the right pluging installed to do HTTP requests, or the HTTP server blocks requests coming from within.
Can you insert some debugging into image.php showing the results of each step? Or post the part of the image.php code where it retrieves the image?
Can you login to the PHP server with SSH and see if you can execute:
wget http://www.norwegianfashion.no/wp-content/uploads/magazine/issue5/siri1_72dpi.jpg
Another solution is to let image.php grab the file from the local disk instead of through a HTTP request, but that requires some redesign of that script.

Resources