Python还很新。我遇到类似this question的问题。我的脚本尝试连接使用wsse消息的Web服务,并使用HTTPS进行设置。我必须使用未经过身份验证的代理。我用肥皂水使用的服务如下:为什么这suds脚本返回urlopen错误[Errno -2]名称或服务未知?
import logging
import suds
import urllib2
from suds.client import Client
from suds.transport.https import HttpAuthenticated
#---These are not real values but represent them.---------
SERVICE_URL = 'https://service.com/1/soap'
SERVICE_USR = 'serviceusr'
SERVICE_PWD = 'servicepwd'
WSDL_URL = 'file:///folder/a.wsdl'
PROXY_NAME = 'proxy'
PROXY_PORT = 80
#----------------------------------------------------------
logging.basicConfig(level = logging.DEBUG)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
proxy_info = {'host': PROXY_NAME,'port': PROXY_PORT}
proxyHandler = urllib2.ProxyHandler({'https':'https://(host)s:%(port)d/' % proxy_info})
opener = urllib2.build_opener(proxyHandler)
urllib2.install_opener(opener)
security = suds.wsse.Security()
token = suds.wsse.UsernameToken(SERVICE_USR, SERVICE_PWD)
security.tokens.append(token)
messageTransport = HttpAuthenticated(username = SERVICE_USR, password = SERVICE_PWD)
messageTransport.urlopner = opener
client = Client(url = WSDL_URL, location = SERVICE_URL, transport = messageTransport)
client.set_options(wsse=security)
result = client.service.ParseValidAddress('1 ABC Street Somwhere')
运行脚本后我收到以下错误:
Error details: <class 'urllib2.URLError'> <urlopen error [Errno -2] Name or service not
known>
于是我就卷曲检查所有的网络位工作如下:
curl -x proxy:80 https://service1.com/1/soap
这将返回一条SOAP消息,指示网络配置和代理正确设置。那么为什么泡沫不会这样做呢?我失败的地方在哪里?
你能说清楚你的代理在哪个端口上运行? –
代理服务器位于端口80.对于HTTPS来说,这很奇怪吗? – GrantVS
你确定你的代理主机'proxy'是可解析的吗?尝试添加“代理”主机的FQDN。换句话说,'PROXY_NAME ='proxy.example.com''。运行在端口80上的代理也被使用或HTTPS并不奇怪。我们在工作中拥有同样的东西。 –