365

I'm using the Requests: HTTP for Humans library and I got this weird error and I don't know what is mean.

No connection adapters were found for '192.168.1.61:8080/api/call'

Anybody has an idea?

Azd325
  • 5,752
  • 5
  • 34
  • 57

5 Answers5

644

You need to include the protocol scheme:

'http://192.168.1.61:8080/api/call'

Without the http:// part, requests has no idea how to connect to the remote server.

Note that the protocol scheme must be all lowercase; if your URL starts with HTTP:// for example, it won’t find the http:// connection adapter either.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
49

One more reason, maybe your url include some hiden characters, such as '\n'.

If you define your url like below, this exception will raise:

url = '''
http://google.com
'''

because there are '\n' hide in the string. The url in fact become:

\nhttp://google.com\n
Kingname
  • 1,302
  • 11
  • 25
  • 19
    Or if your url is accidentally a tuple because of a trailing comma `url = self.base_url % endpoint,` – Christian Long Sep 22 '17 at 15:44
  • @ChristianLong is there any way to convert a string to proper url? Like, can you tell me, what are you doing in your comment? – Ravi Shankar Bharti Aug 11 '18 at 11:50
  • for me it was the ` " "` not sure why, but at some point my single-quoted URL became single-quoted and then double-quoted (maybe pyCharm, maybe github, at some point it must got filtered that way. I had "http://google.com" and then it became " ' http://google.com ' " - after making it just a string it worked again. – Intelligent-Infrastructure Jun 09 '21 at 14:58
7

In my case, I received this error when I refactored a url, leaving an erroneous comma thus converting my url from a string into a tuple.

My exact error message:

    741         # Nothing matches :-/
--> 742         raise InvalidSchema("No connection adapters were found for {!r}".format(url))
    743 
    744     def close(self):

InvalidSchema: No connection adapters were found for "('https://api.foo.com/data',)"

Here's how that error came to be born:

# Original code:
response = requests.get("api.%s.com/data" % "foo", headers=headers)

# --------------
# Modified code (with bug!)
api_name = "foo"
url = f"api.{api_name}.com/data",  # !!! Extra comma doesn't belong here!
response = requests.get(url, headers=headers)


# --------------
# Solution: Remove erroneous comma!
api_name = "foo"
url = f"api.{api_name}.com/data"  # No extra comma!
response = requests.get(url, headers=headers)
Yaakov Bressler
  • 9,056
  • 2
  • 45
  • 69
0

As stated in a comment by christian-long

Your url may accidentally be a tuple because of a trailing comma

url = self.base_url % endpoint,

Make sure it is a string

Gulzar
  • 23,452
  • 27
  • 113
  • 201
0

In my case I used default url for method

def call_url(url: str = "https://www.google.com"):

and url attr was overridden by some method to /some/url

Vitalii Mytenko
  • 544
  • 5
  • 20