In the first place, I thought that I didn't understand the function, so I realized that I had to understand it properly.
I made a base with reference to here. [I tried using Google Cloud Vision](https://www.itbook.info/web/2016/11/google-cloud-vision%E3%82%92%E4%BD%BF%E3%81%A3% E3% 81% A6% E3% 81% BF% E3% 81% 9F.html)
In the first place, what I was doing was outputting the response result obtained by hitting the Cloud Vison API as a file with pickle.dump. Then, weird characters such as ".X ~" were entered at the beginning, and "q." Was entered at the end, which was a problem. Therefore, json.load could not be done for the output file.
response = requests.post(ENDPOINT_URL
,data=json.dumps({"requests": img_requests}).encode()
,params={'key': api_key}
,headers={'Content-Type': 'application/json'})
result = json.dumps(response.json()['responses'], ensure_ascii=False, indent=4)
print(result)
f = open("./output.json", 'wb')
pickle.dump(result, f)
After changing the process as follows, I was able to output it in a form that can be read by json.load.
f = open("./output.json", 'wb')
f.write(result.encode("UTF-8"))
I thought I wrote this and tried it below, Same as the first problem. Lack of understanding. I want to add it when I understand it. Is it because it was in binary format? Anyway, investigation.
f = open("./output.json", 'wb')
f.write(result.encode("UTF-8"))
that's all.
Recommended Posts