0

I couldn´t find any solution to open an image from an indirect URL. The URL is like this: https://mytestsitexyz.de/image.php/image/test?namespace=mytest&x=4711

This will give me a random png image.

Please inform how I can open a PIL image from such an URL. Thanks.I checked How do I read image data from a URL in Python? but it doesn´t solve the problem.

I tried following:

First try:

fd = urllib.urlopen(url)
image_file = io.BytesIO(fd.read())
img = Image.open(image_file)

Error: TypeError: cannot serialize '_io.BufferedReader' object

Second try:

img = Image.open(requests.get(url, stream=True).raw)

Error: <class 'OSError'> cannot identify image file <_io.BytesIO object at 0xb3ba28d0>

third try:

response = requests.get(url)
img = Image.open(BytesIO(response.content))

error: <class 'OSError'> cannot identify image file <_io.BytesIO object at 0xb2e2ae70>

I think the problem is the URL. It isn´t an URL for a direct image file, but it is a PHP that provids an image.

Thanks for helping.

hotte33
  • 1
  • 1
  • 1
    Does this answer your question? [How do I read image data from a URL in Python?](https://stackoverflow.com/questions/7391945/how-do-i-read-image-data-from-a-url-in-python) –  May 27 '21 at 19:49
  • @hotte, please provide a sample of your code so that commenters can help you. Also, what kinds of issues are you experiencing when you run your code (error messages, etc.)? – eatsfood May 27 '21 at 23:20

0 Answers0