**AttributeError: 'str' object has no attribute 'requests'
url = "https://httpbin.org/post"
headers = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (HTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
headers = {"User-Agent" :"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (HTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
}
date = bytes(urllib.parse.urlencode({"name": '666'}), encoding='utf-8')
req = url.requests.Request(uel=url, date=date, headers=headers, method="POST")
response = url.requests.urlopen(req)
print(response.read(), decode("utf-8"))
import requests
import urllib
import json
url = "http://httpbin.org/post"
#headers = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (HTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
headers = {"User-Agent" :"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (HTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
}
data = bytes(urllib.parse.urlencode({"name": '666'}), encoding='utf-8')
# url = "https://www.douban.com"
#req = url.requests.Request(uel=url, date=date, headers=headers, method="POST")
request = urllib.request.Request(url,data,headers=headers)
reponse = urllib.request.urlopen(request).read()
content = json.loads(reponse.decode('utf8'))
print(content)
url = "https://httpbin.org/post"把这个的变量名重新命名,估计是你引入了url库,但是你又重新去了一个变量名url,导致无法使用引入的url库