I'm trying to send a numpy array through the python requests module to a flask server.
First, I compressed the numpy array with zlib, then used base64 to encode the data, then tried to decode and decompress but it's not working.
import numpy as np
import base64
import zlib
import requests
frame = np.random.randint(0,255,(5,5,3)) # dummy rgb image
# compress
data = zlib.compress(frame)
print('compressed')
print(data)
print(len(data))
print(type(data))
data = base64.b64encode(frame)
print('b64 encoded')
print(data)
print(len(data))
print(type(data))
data = base64.b64decode(data)
print('b64 decoded')
print(data)
print(len(data))
print(type(data))
data = zlib.decompress(data)
print('b64 decoded')
I'm getting the following error:
Traceback (most recent call last):
File "client.py", line 26, in <module>
data = zlib.decompress(data)
zlib.error: Error -3 while decompressing data: incorrect header check
data = base64.b64encode(frame) should be
b64encode (data)
You’re accidentally encoding the wrong thing ...
I just realized after considering the extra length for base64 encoded string, I can completely get rid of it.
So, the following code snippet does what I need, it compresses the numpy array, then I can get the original array back without using base64. It gets rid of some of the overhead.
import numpy as np
import base64
import zlib
import requests
frame = np.random.randint(0,255,(5,5,3)) # dummy rgb image
# compress
data = zlib.compress(frame)
print('compressed')
print(data)
print(len(data))
print(type(data))
data = zlib.decompress(data)
print('b64 decoded')
data = np.frombuffer(data, dtype=np.uint8)
print(data)
print(type(data))
Related
i am scraping amazon products image but in some time i get base64 string not image link , so i want to convert this string to image .
i tried this code but got error
CODE:
import base64
from PIL import Image
from io import BytesIO
f = open('C:\\Users\\pc\\Desktop\\base64.txt','r')
data = f.read()
im = Image.open(BytesIO(base64.b64decode(data)))
im.save('C:\\Users\\pc\\Desktop\\image.png', 'PNG')
ERROR:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Invalid base64-encoded string: number of data characters (16369) cannot be 1 more than a multiple of 4
Base64:
data:image/webp;base64,UklGRrQ6AABXRUJQVlA4IKg6AAAw7ACdASo/ASwBPrFKmkekIiEU2r5ERAsE4vviiQDHoCPrX4ipDeU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9tRjWWfny/YscjjtqSEeag1g5sIPqJsVk+GKoYMp99dWszRE6guyX031zsn2z28ZpVWTXBOYzul7itgP5+we/B1iHXFDmrKezWMo85XL0pgkt6bLNEMVpEH4wvw8CZLQQV+52t8kUzAvlLoZCgOtxYLFqNlXrYdkCzLhRbNyxpen9HAGGf6EIcQ7ekVJdTPsU4K5BITZ9H9Qg+saupxI2JW59vTZZhCFVLSGRmLAxmwwkYAmsiUl5GPDej1+mhrElllxtdOtP9E5pVPywG1zmQKB9nrn4Wwof4CCrJnh91LS8VstgAAJzO22meOSbfg/x4NqUJLqMZLAPa8b56F8Uacc/4wZ83YriLaIm4nasz+shx/m8IvER8DGFT2RDSbG33C2CFS53QbrueMbQ5xUxcC9N29SQftdzxtHF6kgnpeVlTHzLixgdefqHsjjxzhiJoSNo8o3p0cbV8lucaw3Ex8J6XH8LKkcVSgPcLeKw0m9ucADQ+1Mugtxz/UwPlbBEctAAAAAA
i know there are many of questions like this one but i didn't find good answer
This data is not exactly base64 notice the prefix data:
data:image/webp;base64,
This data must be stripped first, then it's valid base64 to be processed as an image.
import base64
from PIL import Image
from io import BytesIO
f = open('C:\\Users\\pc\\Desktop\\base64.txt','r')
data = f.read()
prefix = 'data:image/webp;base64,'
cut = data[len(prefix):]
im = Image.open(BytesIO(base64.b64decode(cut)))
im.save('C:\\Users\\pc\\Desktop\\image.png', 'PNG')
I am trying to access data.gov.au datasets through their CKAN data API.
Unfortunately, the data API instructions are slightly outdated and do not seem to work. Instructions found here.
So far, I've worked out that I am meant to query the dataset using urllib.request.
import urllib.request
req = urllib.request.Request('https://data.sa.gov.au/data/api/3/action/datastore_search?resource_id=86d35483-feff-42b5-ac05-ad3186ac39de')
with urllib.request.urlopen(req) as response:
data = response.read()
This produces an object of type bytes that looks like a dictionary data structure, where the dataset seems to be stored in "records:".
I'm wondering how I can convert the data records into a Pandas DataFrame. I've tried converting the bytes object into a string and reading that as a json file, but the output is wrong.
# code that did not work
result = str(data, 'utf-8')
rdata = StringIO(result)
df = pd.read_json(rdata)
df
The output I would like to return looks like this:
Thanks!
Here is a solution that works:
import numpy as np
import pandas as pd
import requests
import json
url = "https://data.sa.gov.au/data/api/3/action/datastore_search?resource_id=86d35483-feff-42b5-ac05-ad3186ac39de"
JSONContent = requests.get(url).json()
content = json.dumps(JSONContent, indent = 4, sort_keys=True)
print(content)
df = pd.read_json(content)
df.to_csv("output.csv")
df = pd.json_normalize(df['result']['records'])
You actually were near the solution. It is only the last step df=pd.json_normalize(df['result']['records']) you were missing.
The following is the string I want to decompress:
eNrNnW1vI9eV598vsN+hoBeDDMxS33vOfajr2DtgU2qbabWoUGr5YbAYFFlFWzv9YKjVsWdfxZnZWQTILOBssjNJJsgEO7OzCyQ2eicZx7En/gbsr7S3SKlVp3SqVaSqLteA1SJVJA/rX/ecc889v7qv/clHDx9E38lPn5w8fvT6ltwWW3/yH/79v3ttJz1LD/Mz/2sUvfbRk1efTN/PH6bRSfb61n7+4flftyL/4kdPXt86/+XVj/zv75+dffDqrVsffvjh9oe4/fj0vVsghLz19r29w8V7XBz78Enm3+X1raenj87f/Un88GR6+vjJ49lZPH388FV/XLw8amthx9KS/EH+MH90Fj1KH+bUmOWxrw6fnD/z+tbZ6dP8xfP3n+SDp6en/rV7j6fpg/z8z+dvvXxz/7EfPMg/OvqLD/IXz5//5f3HJ9M8enjyaDSdPj31X1T4d04/unj09NHk8dNHWZ5tlV7IWXyUTh7k9KCXffbl39Ozs9OTydOz/PyNdvKz9OTBMNuKzvxLXt/yh5w88qfhVqNXv5E/6p+elV77xP/90XtNX+5fu+4nD8/yh4PHWb72Z9/oxfuPz05mJ9P0zF/vT9Z+l9un6aNs7Vfv5E+mpycfFCas/R4H6enZ/uO1X/7W4cGpv55Lr8/y6cnD9EHTNxgvrr4bvsn9RydnN3yL/fym7zB8mL6X3z99sPa5PMwfPPCH39CMb5/9xfDRICVjcoVRdeg92pPB44eFp1n7m7xx+vjpB3dO8gfrX9v38tP38sUFfrO36H+niSCv3XqJ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oLOpWe2sCyoW6VQU6Wys580XBl+7tZ9/uOOtOczPFk+9duvc5uU/6UP/7Gu3Lo74f1DSNzk=
I have tried zlib:
import zlib
decompressed_data = zlib.decompress(data)
I get the following error:
TypeError: a bytes-like object is required, not 'str'
Then I did:
data = bytes(data, "utf-8")
decompressed_data = zlib.decompress(data)
I get an error again:
Error -3 while decompressing data: incorrect header check
You first need to decode the base64, then zlib decompress:
import zlib, base64
decompressed_data = zlib.decompress(base64.b64decode(data))
Looking at your data, it appears to be UTF-8 encoded XML, so we're almost there:
xml = decompressed_data.decode("utf-8")
Working on this challenge for my Python course and cant seem to figure out how to continue. I think what i have so far is correct but any input would be amazing.
Goal: Decode the base64 blob included below
import base64
import gzip
import StringIO
# This is our base64 encoded string
data = 'H4sIAAAAAAAAAL1X6W+j....'
def main():
# Decode the base64 string into a variable
decoded = base64.b64decode(data)
# Create a variable that holds a stream living in a buffer
# Decompress our stream
# Print it to the screen
if __name__ == '__main__':
main()
Here is a solution with detailed explanation
#Going by the comments in your code
#content of data variable is first gzip compressed and then base64 encoded
#In order to get the original content back, you must,
#first base64 decode and then gzip uncompress it
#since gzip works on file objects, StringIO is to be used
#StringIO module implements a file-like class, that reads and writes a string buffer
import StringIO
import base64
import gzip
data = "...." #gzip compressed => base64 encoded
b64decoded = base64.b64decode(data) # base64 decode
inputstream = StringIO.StringIO();
inputstream.write(b64decoded)
inputstream.seek(0)
#
uncompressGzip = gzip.GzipFile(fileobj=inputstream, mode='rb') # gzip uncompress
originalData = uncompressGzip.read()
print(originalData)
Here is a simple test, compress => encode => decode => uncompress
import StringIO
import base64
import gzip
buf = StringIO.StringIO()
compressGzip = gzip.GzipFile(fileobj=buf, mode="wb")
compressGzip.write("Hello, how are you?")
compressGzip.close()
buf.seek(0)
data = base64.b64encode(buf.getvalue())
# your solution from this point onwards
b64decoded = base64.b64decode(data) # base64 decode
inputstream = StringIO.StringIO();
inputstream.write(b64decoded)
inputstream.seek(0)
#
uncompressGzip = gzip.GzipFile(fileobj=inputstream, mode='rb') # gzip uncompress
originalData = uncompressGzip.read()
print(originalData)
I know I can save an RGB array to a file using
from matplotlib.pyplot import imsave
rgb = numpy.zeros([height,width,3], dtype=numpy.uint8)
paint_picture(rgb)
imsave("/tmp/whatever.png", rgb)
but now I want to write the PNG to a byte buffer instead of a file so I can later transmit those PNG bytes via HTTP. There must be no temporary files involved.
Bonus points if the answer has variations that support formats other than PNG.
Evidently imsave supports "file-like objects" of which io.BytesIO is the one I need:
buffer = BytesIO()
imsave(buffer, rgb)
encoded_png = buffer.getbuffer()
#and then my class derived from BaseHTTPRequestHandler can transmit it as the response to a GET
self.send_response(200)
self.send_header("Content-Type", "image/png")
self.end_headers()
self.wfile.write(encoded_png)
return
If you want to do a file upload (any type of picture)
Send file using POST from a Python script
But if you want to send raw png data you can reread the file and encode it in base64. Your server just have to decode base64 and write the file.
import base64
from urllib.parse import urlencode
from urllib.request import Request, urlopen
array_encoded = ""
with open("/tmp/whatever.png") as f:
array_encoded = base64.encode(f)
url = 'https://URL.COM' # Set destination URL here
post_fields = {'image': array_encoded} # Set POST fields here
request = Request(url, urlencode(post_fields).encode())
responce = urlopen(request).read()
print(responce)
Code not tested!!!!!!!