【发布时间】:2018-09-27 02:37:10
【问题描述】:
我有一个 python 脚本,它使用请求库通过其 Web 界面连接到设备。它使用带有 https 连接的 url。
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 代码(exec 函数)触发时。它抛出这个错误
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