请求库:无法建立新连接:[Errno 13]权限被拒绝 [英] requests library: Failed to establish a new connection: [Errno 13] Permission denied

查看:100
本文介绍了请求库:无法建立新连接:[Errno 13]权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

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?

推荐答案

setsebool -P httpd_can_network_connect on

setsebool -P httpd_can_network_connect on

这篇关于请求库:无法建立新连接:[Errno 13]权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆