请求库:建立新连接失败:[Errno 13]权限被拒绝

问题描述 投票:1回答:1

我有一个python脚本,该脚本使用请求库通过其Web界面连接到设备。它使用带有https连接的网址。

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))

[当我尝试从命令行执行它时,它可以完美运行(即使对于apache用户)。但是,当它是通过来自Web门户的php代码(执行函数)触发时。会引发此错误

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',))",),)

我不确定是什么原因,因为apache用户能够执行它并建立连接。为什么在通过PHP代码执行时未连接?

php python-3.x apache python-requests
1个回答
0
投票

setsebool -P httpd_can_network_connect on

© www.soinside.com 2019 - 2024. All rights reserved.