Below code works absolutely fine for me when I used python's requests library.
(当我使用python的请求库时,以下代码对我来说绝对正常。)
I want the same action to be done using urllib in Python3 library. (我希望使用Python3库中的urllib进行相同的操作。)
import requests
files = {'FileData': open(sample.png, 'rb')}
headers={
"Authorization": "Basic ***********"
}
result = requests.post("https://my_sample_api_url",headers=headers,files=files)
I tried to do this post call in urllib like this, which gives me 400 Bad Request Error.
(我试图这样在urllib中进行此调用,这给了我400错误的请求错误。)
import urllib
from urllib.request import Request, urlopen
files = {'FileData': open("sample.png", "rb")}
headers={
"Authorization": "Basic ************"
}
data_bytes = urllib.parse.urlencode(files).encode("utf-8")
result_req = Request("https://my_sample_api_url", data=data_bytes, headers=headers)
result = urlopen(image_result_req)
How can I convert this code to urllib?
(如何将该代码转换为urllib?)
ask by Prathyush P translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…