I am trying to convert a HTTP POST into Python and am not sure how to go about doing this.
I have the HTTP Request:
POST vision/v1/ocr?language=unk&detectOrientation =true
Content-Type: application/json
Host: api.projectoxford.ai
Content-Length: 95
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••
{ "Url": "exampleurl.com"}
As well as the URL request and need help on whether or not I am doing this correctly.
import urllib.parse
import urllib.request
url = "urlrequest.com"
values = {"Url":
https://exampleurl.com}
data = url.lib.parse.urlencode(values)
data = data.encode('utf-8')
req = urllib.request.Request(url, data)
with urllib.request.urlopen(req) as response:
the_page = response.read()
I am getting an HTTTPError:
HTTP Error 400: Bad Request.
reqis undefined. Show correct code.dataafter encoding it. Please at least provide us with code that is free from syntax errors so we can determine if not usingdatacould be the issue.