import urllib.parse
import urllib.request
url="http://httpbin.org/post"
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"}
data = bytes(urllib.parse.urlencode({"hello":"world"}),encoding="utf-8")
req= urllib.request.Request(url=url,data=data,headers=headers,method="post")
response = urllib.request.urlopen(req)
print(response.read().decode("utf-8"))
报错
urllib.error.HTTPError: HTTP Error 400: Bad Request