我想发送POST请求。这是我的代码
import requests
url = "http://localhost:3000/oauth2/token"
data = {'grant_type': 'client_credentials',
'client_id': 'ClientCredentialsClient',
'client_secret': 'Ultrasecretstuff'}
headers = {'Content-type': 'application/x-www-form-urlencoded',
'Authorization': 'auth'}
r = requests.post(url, data=data, headers=headers)
print(r)
我的脚本没有得到响应,而是死机了,当我停止脚本时,我得到了这个错误
File "get_token.py", line 12, in <module>
r = requests.post(url, data=data, headers=headers)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 520, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 630, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse(buffering=True)
File "/usr/lib/python2.7/httplib.py", line 1121, in getresponse
response.begin()
File "/usr/lib/python2.7/httplib.py", line 438, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.7/httplib.py", line 394, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "/usr/lib/python2.7/socket.py", line 480, in readline
data = self._sock.recv(self._rbufsize)x
有人可以告诉我我在做什么错吗?
答案 0 :(得分:0)
requests.post
没有参数标题,请将其删除。