简体   繁体   中英

requests library: Failed to establish a new connection: [Errno 13] Permission denied

I have a python script which uses requests library to connect to a device with its web-interface. It uses a url with https connection.

sess = requests.Session()
try:
          resp = sess.post('https://' + device + '/url_admin/login.cgi', data=login_data, verify=False)
except Exception as e:
            template = "Exception: {0}\nArguments: {1!r}"
            print(template.format(type(e).__name__, e.args))

When I try to execute it from command line it works perfectly (even with apache user). However, when it is triggered with a php code (exec function) from a web-portal. it throws this error

Exception: ConnectionError
Arguments: (MaxRetryError("HTTPSConnectionPool(host='some.device.com', port=443): Max retries exceeded with url: /url_admin/login.cgi (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f55aa8e6550>: Failed to establish a new connection: [Errno 13] Permission denied',))",),)

I am not sure what is the reason because the apache user is able to execute it and make connection. Why it is not connecting when executed by php code?

setsebool -P httpd_can_network_connect on

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM