[Solved] requests.exceptions.InvalidSchema: No connection adapters were found for

At the beginning of learning, when using requests, I knocked on demo

1 import requests
2 
3 params = {
4     "name": "name",
5     "password": "gao"
6 }
7 
8 res = requests.get("127.0.0.1:8000", params=params)

There was an error in the result

C:\Users\gaoyu\Envs\py_path1\Scripts\python.exe D:/python3.6/spider/demo/requests_test.py
Traceback (most recent call last):
  File "D:/python3.6/spider/demo/requests_test.py", line 8, in <module>
    res = requests.get("127.0.0.1:8000", params=params)
  File "C:\Users\gaoyu\Envs\py_path1\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\gaoyu\Envs\py_path1\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\gaoyu\Envs\py_path1\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\gaoyu\Envs\py_path1\lib\site-packages\requests\sessions.py", line 640, in send
    adapter = self.get_adapter(url=request.url)
  File "C:\Users\gaoyu\Envs\py_path1\lib\site-packages\requests\sessions.py", line 731, in get_adapter
    raise InvalidSchema("No connection adapters were found for '%s'" % url)
requests.exceptions.InvalidSchema: No connection adapters were found for '127.0.0.1:8000'

Finally, it is found that the reason is very simple, that is, the URL needs to be preceded by http://

Similar Posts: