magictroy / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

installed application throws CertificateHostnameMismatch #346

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
[Use this form for both apiclient and oauth2client issues]
I have a Google Service Account which is being used by an installed application 
to upload files into GCS, and then send a POST request to a GAE Module.

The upload of files to GCS works great, but when the credentials of the default 
service account are used to send a POST to a GAE Module (in its yaml file the 
login for the GAE Module handler is declared to be required), the 'Server 
presented certificate does not match' the URI

After searching this site, as well as using Google Search, I have not 
discovered a solution to this problem, and not much general info about this 
type of problem. I'm using the latest version of the Goolge API Python client 
(1.9.24)

Here's the stack trace:

Traceback (most recent call last):
  File "gcs_bq_file_uploader.py", line 302, in main
    gae_endpoint = discovery.build(config._GAE_API, config._GAE_API_VERSION, discoveryServiceUrl=dis
covery_url, http=http_auth)
  File "C:\Python27\Lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Python27\lib\site-packages\google_api_python_client-1.4.1-py2.7.egg\googleapiclient\disco
very.py", line 197, in build
    resp, content = http.request(requested_url)
  File "C:\Python27\Lib\site-packages\oauth2client\client.py", line 562, in new_request
    redirections, connection_type)
  File "C:\Python27\Lib\site-packages\httplib2\__init__.py", line 1608, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, re
directions, cachekey)
  File "C:\Python27\Lib\site-packages\httplib2\__init__.py", line 1350, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "C:\Python27\Lib\site-packages\httplib2\__init__.py", line 1272, in _conn_request
    conn.connect()
  File "C:\Python27\Lib\site-packages\httplib2\__init__.py", line 1047, in connect
    'host %s: %s' % (hostname, cert), hostname, cert)
CertificateHostnameMismatch: Server presented certificate that does not match 
host www.ethereal-shap
e-89619.appspot.com: {'notAfter': 'Oct 13 00:00:00 2015 GMT', 'subjectAltName': 
(('DNS', '*.appspot.
com'), ('DNS', '*.thinkwithgoogle.com'), ('DNS', '*.withgoogle.com'), ('DNS', 
'appspot.com'), ('DNS'
, 'thinkwithgoogle.com'), ('DNS', 'withgoogle.com')), 'subject': 
((('countryName', u'US'),), (('stat
eOrProvinceName', u'California'),), (('localityName', u'Mountain View'),), 
(('organizationName', u'G
oogle Inc'),), (('commonName', u'*.appspot.com'),))}
INFO:root:None
INFO:root:------------------------------------------------------------

What steps will reproduce the problem?
1. Running the code
2.
3.

What is the expected output? What do you see instead?
See stack trace shown above. Source code is attached. And the yaml of the 
target GAE Module is included as well (if that is of any help).

What version of the product are you using? On what operating system?
Product version 1.9.24. Windows 7 Professional 32-bit

Please provide any additional information below.
This is my first attempt at sending a POST request to a GAE Module from an 
installed application, so my guess is I've got an easily detected bug in my 
code, or I'm entirely missing some critical bit of code.

Original issue reported on code.google.com by wfs.deve...@gmail.com on 23 Jul 2015 at 3:58

Attachments:

GoogleCodeExporter commented 8 years ago
FYI, 
I have worked past this problem by making the following change to the code:
http_auth = credentials.authorize(httplib2.Http())
is now:
http_auth = 
credentials.authorize(httplib2.Http(disable_ssl_certificate_validation=True))

But, doing so has resulting in the repressing the prior certificate error 
message, while triggering another error (likely caused by my code, which I am 
now investigating):

Traceback (most recent call last):
  File "gcs_bq_file_uploader.py", line 304, in main
    gae_endpoint = discovery.build(config._GAE_API, config._GAE_API_VERSION, discoveryServiceUrl=dis
covery_url, http=http_auth)
  File "C:\Python27\Lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Python27\lib\site-packages\google_api_python_client-1.4.1-py2.7.egg\googleapiclient\disco
very.py", line 197, in build
    resp, content = http.request(requested_url)
  File "C:\Python27\Lib\site-packages\oauth2client\client.py", line 562, in new_request
    redirections, connection_type)
  File "C:\Python27\Lib\site-packages\httplib2\__init__.py", line 1608, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, re
directions, cachekey)
  File "C:\Python27\Lib\site-packages\httplib2\__init__.py", line 1403, in _request
    redirections=redirections - 1)
  File "C:\Python27\Lib\site-packages\oauth2client\client.py", line 552, in new_request
    headers['user-agent'] = self.user_agent + ' ' + headers['user-agent']
TypeError: can only concatenate tuple (not "str") to tuple

Hopefully, I'll resolve this one shortly.

Original comment by wfs.deve...@gmail.com on 23 Jul 2015 at 6:00