【问题标题】:requests library: Failed to establish a new connection: [Errno 13] Permission denied请求库:无法建立新连接:[Errno 13] 权限被拒绝
【发布时间】: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


    【解决方案1】:

    setsebool -P httpd_can_network_connect on

    【讨论】:

    • 你是救生员。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 2017-04-20
    • 2011-06-11
    • 2014-07-15
    • 2015-07-17
    • 2016-07-25
    • 2013-06-12
    相关资源
    最近更新 更多