A
A
AlessandrIT2019-09-12 17:49:33
Python
AlessandrIT, 2019-09-12 17:49:33

Is it possible to bypass the download of the image for further processing?

The program is supposed to process the image at the given URL.
Data contains a URL as a list element
. Now I write the received data to a file, then I open it again (in the same code) and perform the necessary manipulations.
Is something similar as described below possible?

img2 = requests.get(data[1].strip()[0:-6])
img = io.imread(img2.content)

I will say right away - the above code knocks out an error
"TypeError: a bytes-like object is required, not 'str'"

Is it possible to avoid the seemingly unnecessary writing to a file?
PS Tried b = bytearray.fromhex(str(img2.content))
Caught
Traceback (most recent call last):
  File "C:\Py\Projects\1\photoexec.py", line 40, in <module>
    b = bytearray.fromhex(img2.content)
TypeError: fromhex() argument must be str, not bytes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlessandrIT, 2019-09-12
@AlessandrIT

Thanks for the help sim3x
https://2.python-requests.org/en/master/user/quick...
img = io.imread(BytesIO(img2.content))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question