问题
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?
回答1:
setsebool -P httpd_can_network_connect on
来源:https://stackoverflow.com/questions/52528590/requests-library-failed-to-establish-a-new-connection-errno-13-permission-de