In on of my Django view´s I am making a request to another webserver via requests, this code works perfect when I run the code with the development server. It looks like that:
import requests
r = requests.post('http://www.example.org')
return r.text
But when I Deploy this an apaches www-data user is running it it throws this error:
ConnectionError
HTTPConnectionPool(host='www.example.com', port=80): Max retries exceeded
with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection
object at 0x7f23e917ba58>:Failed to establish a new connection:[Errno -2]
Name or Service not known'))
But I can run the code as root user from a seperate script on the Deployment server without a problem this is why i think it is a permission problem. But i have no Idea how to solve this.
Thanks in advance!
Related
I have recently begun a project for my work that involves me having to connect to an accounting application's API (Kuali).
I have only recently begun working with APIs and am having a great degree of difficulty connecting to this server. When running the following code I receive this error:
import requests
requests.get('https://university.kuali.co/api/v1/auth/authenticate','Authorization: Basic mykeyhere')
print(requests.status_codes)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='university.kuali.co', port=443): Max retries exceeded with url: /api/v1/auth/authenticate?Authorization:%20Basic%20mykeyhere (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x109c276d0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
I would greatly appreciate any help as this project would save a huge amount of my time.
The link to the API documentation can be found below.
https://developers.kuali.co/#general
Authorisation Should be under headers
requests.get(url,headers={“Authorisation”:”Basic your key here”})
In docusign version 3.1.0, python version 3.5 and 3.6 in sandbox mode, I'm getting following error:
MaxRetryError at /return_url/8a2108d2-ee01-4c1a-ae53-47d305a92988/
HTTPSConnectionPool(host='https', port=443):
Max retries exceeded with url: //account-d.docusign.com/oauth/token
(Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection
object at 0x7fe15ca63438>: Failed to establish a new connection:
[Errno -2] Name or service not known',))
From the error message, it looks like you're not specifying the URL correctly.
You should be doing a POST to https://account-d.docusign.com/oauth/token
It looks like you're close to that but not correct. Eg, why does the error message show that host='https' -- The host should be account-d.docusign.com or https://account-d.docusign.com
Are you using an OAuth Authorization Code Grant library for Python? I always recommend using a library. See our eg-03-python-auth-code-grant example which uses the flask_oauthlib.
i'm trying to send GET request from my Django app to Spring app hosted in my local machine.
I've tested sending requests to another websites outside localhost and it works perfectly. Problem appears when it comes to sending to http://localhost:port.
This is function which is sending requests in my Django app. It works for url1 but doesnt for url2.
def send_mail(request):
url1 = "https://httpbin.org/get"
url2 = "http://localhost:5000"
response = requests.get(url2)
return HttpResponse(response)
Here's an error that shows wherever i try send request to localhost.
HTTPConnectionPool(host='localhost', port=5000): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused'))
I have this host: http://retsau.torontomls.net:7890/and I want to access http://retsau.torontomls.net:7890/rets-treb3pv/server/login, how can I accomplish this using Python Requests? All my attempts till now have failed.
I also followed the solution here - Python Requests - Use navigate site by servers IP and came up with this -
response = requests.get(http://206.152.41.279/rets-treb3pv/server/login, headers={'Host': retsau.torontomls.net})
but that resulted in this error:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='206.152.41.279', port=80): Max retries exceeded with url: /rets-treb3pv/server/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10a4f6d84>: Failed to establish a new connection: [Errno 60] Operation timed out',))
Funny thing is everything seems to work perfectly fine on Postman, I am able to access all sorts of URLs on that server, from logging in to searching for something.
You left out the port number (7890) from the URL to your get call:
response = requests.get('http://206.152.41.279:7890/rets-treb3pv/server/login', headers={'Host': 'retsau.torontomls.net'})
# ^^^^ Add this
Also, unless you actually have a specific reason for accessing the site by IP address, it would make more sense to put the FQDN in the URL rather than the Host header:
response = requests.get('http://retsau.torontomls.net:7890/rets-treb3pv/server/login')
I have the follow code:
res = requests.get(url)
I use multi-thread method that will have the follow error:
ConnectionError: HTTPConnectionPool(host='bjtest.com', port=80): Max retries exceeded with url: /rest/data?method=check&test=123 (Caused by : [Errno 104] Connection reset by peer)
I have used the follow method, but it still have the error:
s = requests.session()
s.keep_alive = False
OR
res = requests.get(url, headers={'Connection': 'close'})
So, I should how do it?
BTW, the url is OK, but it only can be visited internal, so the url have no problem. Thanks!
you run your script on Mac? I also meet similar problem, you can execute ulimit -n to check how many files you can handle in a time.
you can use below to enlarge the configuration.
resource.setrlimit(resource.RLIMIT_NOFILE, (the number you reset,resource.RLIM_INFINITY))
hoping can help you.
my blog which associated with your problem
I got a similar case, hopefully it can save some time to you:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8001): Max retries exceeded with url: /enroll/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10f96ecc0>: Failed to establish a new connection: [Errno 61] Connection refused'))
The problem was actually silly... the localhost was down at port 8001! Restarting the server solved it.
The error message (which is admittedly a little confusing) actually means that requests failed to connect to your requested URL at all.
In this case that's because your url is http://bjtest.com/rest/data?method=check&test=123, which isn't a real website.
It has nothing to do with the format you made the request in. Fix your url and it should (presumably) work for you.