400

I'm using the Requests: HTTP for Humans library and I got this error:

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

What does this mean and how can I fix it?

8 Answers 8

702

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.

Sign up to request clarification or add additional context in comments.

Comments

54

Maybe your URL includes some hidden characters, such as \n.

If you define your URL like below, the exception you have seen will be raised:

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

because there are \n hidden in the string. The URL in fact becomes:

\nhttp://google.com\n

4 Comments

Or if your url is accidentally a tuple because of a trailing comma url = self.base_url % endpoint,
@ChristianLong is there any way to convert a string to proper url? Like, can you tell me, what are you doing in your comment?
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 "google.com" and then it became " ' google.com ' " - after making it just a string it worked again.
A trailing comma made my url a tuple... Thanks for getting to me check the silly stuff!
10

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)

Comments

3

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

3 Comments

changing the tuple to a string gave me the same error. Can you give an example?
Not sure what you mean by changing to string. I meant url = self.base_url % endpoint without the comma
Similar case happens by me: I have incidentally placed scopes around the url, e.g. my_url = ['https://my_server/my_link/' + 'rest/api/2/search/...'] In the error-message it's quite hard to recognize - what is the root cause (you can consider scopes as value formatting). But the one with comma is more tricky ;-)
1

In my case the issue was that I had defined URLs as a value to an environment variable in an .env, like this:

MY_ENDPOINT="<url>"

The problem with this is that, at least Docker, takes the quotes as part of the URL string, making the URL invalid. Removing the quotes solved the issue for me:

MY_ENDPOINT=<url>

Comments

0

I was trying to call json-server with requests, however I was unable to call the API.

The root problem was, it requires to be included the protocol scheme i.e. http://

import requests

url = 'http://localhost:3000/employees'

try:
  response = requests.get(url)
  if response:
    print(response.json())
except requests.exceptions.RequestException as ex:
  print(ex)

Also, for http requests - the requests should be wrapped with try/except block - to better debug the cause of the problem.

Comments

0

For me the issue was I was passing url as below on windows:

MY_ENDPOINT="<url>"

I had to change that to below without greater than and less than symbol to get rid of this error.

MY_ENDPOINT="url"

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.