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?
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?
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.
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
url = self.base_url % endpoint,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)
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
url = self.base_url % endpoint without the commamy_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 ;-)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>
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.