尝试连接到localhost时出现InvalidSchema

时间:2014-03-18 13:28:10

标签: python python-requests

我正在尝试使用python消息库执行post请求。我有

>>> import requests
>>> p = { 
'email':'*****',
'passwd':'*****',
}
>>> r = requests.post('127.0.0.1:8000/mysite/',data=p)

这是追溯:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "c:\envs\r1\lib\site-packages\requests\api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File "c:\envs\r1\lib\site-packages\requests\api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "c:\envs\r1\lib\site-packages\requests\sessions.py", line 383, in request
    resp = self.send(prep, **send_kwargs)
  File "c:\envs\r1\lib\site-packages\requests\sessions.py", line 481, in send
    adapter = self.get_adapter(url=request.url)
  File "c:\envs\r1\lib\site-packages\requests\sessions.py", line 526, in get_adapter
    raise InvalidSchema("No connection adapters were found for '%s'" % url)
InvalidSchema: No connection adapters were found for '127.0.0.1:8000/mysite/'

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:10)

您的网址缺少该计划;使用http://127.0.0.1:8000/mysite/

r = requests.post('http://127.0.0.1:8000/mysite/', data=p)