googleads-python-lib icon indicating copy to clipboard operation
googleads-python-lib copied to clipboard

Host Fails to Respond through Proxy

Open dreyco676 opened this issue 12 years ago • 8 comments

I have successfully run the script 'get_keyword_ideas.py' on my local machine without a proxy. When I deploy the script on a server with a proxy and I set the googleads.yaml https proxy I am unable to connect to the host.

I have verified that I am able to hit the following:

  • I am able to resolve googleapis.com, adwords.google.com with other applications
  • I have tried setting the proxy via os.environ['https_proxy'] = 'https://example:1234'

Error

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred: urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

dreyco676 avatar Mar 28 '14 18:03 dreyco676

I'm on python 3.3.4 on a windows 7 x64 system.

dreyco676 avatar Mar 28 '14 18:03 dreyco676

We're looking into this.

jdilallo avatar Apr 01 '14 15:04 jdilallo

Let me know if you need any additional information, I'd be happy to provide.

I did read that this might have something to do with urllib and that urllib2 may handle the proxy differently.

dreyco676 avatar Apr 01 '14 16:04 dreyco676

Same problem here guys.. I'm trying to make this work for one month now. Before I was using the old python library.. but now I'm using this new one.

Here's my info so far:

Proxy: Squid 3.1.10 OS: CentOS 6.5 Python 2.7.6

I'm opening the client like this: client = adwords.AdWordsClient(DEVELOPER_TOKEN, oauth2_client, USER_AGENT, CLIENT_CUSTOMER_ID,https_proxy='proxy.qa.vmcommerce.intra:3128')

But the code stuck on the point where suds try to make a request to get the WSDL info from url: https://adwords.google.com/api/adwords/cm/v201402/CampaignService?wsdl .

On adwords.py (method GetService) you have:

client = suds.client.Client( self._SOAP_SERVICE_FORMAT % (server, _SERVICE_MAP[version][service_name], version, service_name))

I think the problem here is that the https_proxy info is not being passed to suds Client constructor. The https_proxy config is being used a few lines after this: if self.https_proxy: client.set_options(proxy={'https': self.https_proxy})

And then I got this exception: Traceback (most recent call last): File "get_campaigns.py", line 16, in campaign_service = client.GetService('CampaignService', version='v201402') File "/opt/python2.7/lib/python2.7/site-packages/googleads-1.0.3-py2.7.egg/googleads/adwords.py", line 193, in GetService (server, _SERVICE_MAP[version][service_name], version, service_name)) File "/opt/python2.7/lib/python2.7/site-packages/suds_jurko-0.6-py2.7.egg/suds/client.py", line 115, in init self.wsdl = reader.open(url) File "/opt/python2.7/lib/python2.7/site-packages/suds_jurko-0.6-py2.7.egg/suds/reader.py", line 150, in open d = self.fn(url, self.options) File "/opt/python2.7/lib/python2.7/site-packages/suds_jurko-0.6-py2.7.egg/suds/wsdl.py", line 136, in init d = reader.open(url) File "/opt/python2.7/lib/python2.7/site-packages/suds_jurko-0.6-py2.7.egg/suds/reader.py", line 74, in open d = self.download(url) File "/opt/python2.7/lib/python2.7/site-packages/suds_jurko-0.6-py2.7.egg/suds/reader.py", line 92, in download fp = self.options.transport.open(Request(url)) File "/opt/python2.7/lib/python2.7/site-packages/suds_jurko-0.6-py2.7.egg/suds/transport/https.py", line 62, in open return HttpTransport.open(self, request) File "/opt/python2.7/lib/python2.7/site-packages/suds_jurko-0.6-py2.7.egg/suds/transport/http.py", line 67, in open return self.u2open(u2request) File "/opt/python2.7/lib/python2.7/site-packages/suds_jurko-0.6-py2.7.egg/suds/transport/http.py", line 132, in u2open return url.open(u2request, timeout=tm) File "/opt/python2.7/lib/python2.7/urllib2.py", line 404, in open response = self._open(req, data) File "/opt/python2.7/lib/python2.7/urllib2.py", line 422, in _open '_open', req) File "/opt/python2.7/lib/python2.7/urllib2.py", line 382, in _call_chain result = func(*args) File "/opt/python2.7/lib/python2.7/urllib2.py", line 1222, in https_open return self.do_open(httplib.HTTPSConnection, req) File "/opt/python2.7/lib/python2.7/urllib2.py", line 1184, in do_open raise URLError(err) urllib2.URLError: urlopen error [Errno 101] Network is unreachable

Please let me know if you need any tests from my end.

rodrigoreis22 avatar Apr 04 '14 19:04 rodrigoreis22

New progress:

If you pass the parameter proxy= to suds Client it will work:

from suds.client import Client import logging

logging.basicConfig(level=logging.DEBUG) logging.getLogger('suds.transport').setLevel(logging.DEBUG)

url = 'https://adwords.google.com/api/adwords/cm/v201402/CampaignService?wsdl' client = Client(url, proxy={ 'http' : 'http://proxy.qa.vmcommerce.intra:3128', 'https' : 'http://proxy.qa.vmcommerce.intra:3128' }) print client

rodrigoreis22 avatar Apr 04 '14 22:04 rodrigoreis22

Code forked and working fine now on https://github.com/rodrigoreis22/googleads-python-lib

rodrigoreis22 avatar Apr 04 '14 22:04 rodrigoreis22

Alright, so it seems like there's 2 problems here. I'll work in the fix rodrigoreis22 mentioned: passing the proxy into the Client constructor instead, so the fetching of the WSDL uses the proxy too.

As for the original reported issue by dreyco676, I'm less certain. Was this the cause of your problem too? It seems that urllib2 isn't designed to use a proxy at an https:// URL, resulting in timeouts or connection reset by peer messages. Using a proxy with an http:// address resolves this, but I'm not certain of the security implications yet.

jdilallo avatar Apr 08 '14 15:04 jdilallo

The issues brought up earlier have been resolved, though feel free to comment if you have additional questions.

msaniscalchi avatar May 23 '14 15:05 msaniscalchi