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

不羁的心 提交于 2021-02-10 17:28:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!