curl --noproxy“ *”在Python的请求模块中等效

时间:2018-12-12 19:45:56

标签: python curl python-requests

我正在尝试使用Python的-- Delete index if exists IF EXISTS(SELECT TOP 1 1 FROM sys.indexes indexes INNER JOIN sys.objects objects ON indexes.object_id = objects.object_id WHERE indexes.name ='Your_Index_Name' AND objects.name = 'Your_Table_Name') BEGIN PRINT 'DROP INDEX [Your_Index_Name] ON [dbo].[Your_Table_Name]' DROP INDEX [our_Index_Name] ON [dbo].[Your_Table_Name] END GO 模块访问网络中服务器上的API,但遇到502 Bad Gateway错误。当我尝试使用request做等效的操作时,出现相同的错误,这是因为请求正试图通过代理服务器运行。这是curl的输出:

curl

作为顶部的输出状态,$ curl -v -k -u username:password https://hostname:port/some/api/endpoint * Uses proxy env variable no_proxy == 'hostname' * Uses proxy env variable https_proxy == 'http://10.3.0.40:10256' * Trying 10.3.0.40... * TCP_NODELAY set % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 10.3.0.40 (10.3.0.40) port 10256 (#0) * allocate connect buffer! * Establish HTTP proxy tunnel to hostname:port * Server auth using Basic with user 'user' > CONNECT hostname:port HTTP/1.1 > Host: hostname:port > User-Agent: curl/7.61.1 > Proxy-Connection: Keep-Alive > < HTTP/1.0 502 Bad Gateway < Server: Zscaler/5.6 < Content-Type: text/html < Connection: close < * Received HTTP code 502 from proxy after CONNECT * CONNECT phase completed! * Closing connection 0 curl: (56) Received HTTP code 502 from proxy after CONNECT 正在自动实现我在环境变量中拥有的curl变量,这是其他Python任务所必需的。为了避免这种情况,我可以将HTTP_PROXY传递给--noproxy "*",并且该请求不再尝试通过代理运行。

我想尝试与Python的curl模块一起使用。我知道request也会自动从环境变量中读取,因此我尝试绕过在代码中指定requests的地方:

proxies=None

但是我仍然得到502 Bad Gateway。在查看有关SO的一些问题时,似乎可以指定response = requests.get('https://hostname:port/some/api/endpoint', proxies=None, auth=(USER, PASS)) 环境变量并提供不应使用代理的URL。我尝试用NO_PROXYhttps://hostnamehttps://hostname:porthttps://hostname/*https://hostname:port/*填充该变量。这些似乎都不起作用。 (这些格式是否正确?)

我如何获得hostname才能使用curl的requests的等效功能?

1 个答案:

答案 0 :(得分:1)

.as-console-wrapper { max-height: 100% !important; top: 0; }设置为proxies就像忽略它。您想通过传递值来指定http和https代理为None

None

转到proxies={'http': None, 'https': None} 函数。

关于requests.get(或NO_PROXY),其值为一个域名,因此您不应在其中添加no_proxyhttp://在其值的前面,仅在您使用的情况下使用域名https://

相关问题