Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httplib2 RedirectMissingLocation: Redirected but the response is missing a Location: header. #891

Closed
mengyyy opened this issue May 2, 2020 · 5 comments
Assignees
Labels
needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue.

Comments

@mengyyy
Copy link

mengyyy commented May 2, 2020

Environment details

  • OS type and version: Ubuntu16.04
  • Python version: python3.6 x64
  • pip version: 20.1
  • google-api-python-client version: 1.8.2
  • httplib2 version: 0.17.3

Steps to reproduce

  1. upload file

Code example

file_metadata = {"name": file_name, "parents": [parent_id]}
media = MediaFileUpload(file_path, resumable=True, chunksize=chunksize)
files_api.create(body=file_metadata, media_body=media, fields="*", supportsTeamDrives=True).execute()

Stack trace


2020-05-02 23:31:14.093 | ERROR    | mengy_gdrive:upload:394 - upload failed | File /home/ming_gdrive.py, line 392, in upload
    381  def upload(self, file_path, remote_dir, chunksize=8 * 2 ** 20):
 (...)
    388          return False, None
    389      file_metadata = {"name": file_name, "parents": [parent_id]}
    390      media = MediaFileUpload(file_path, resumable=True, chunksize=chunksize)
    391      try:
--> 392          result = self.files_api.create(body=file_metadata, media_body=media, fields="*", supportsTeamDrives=True).execute()
    393      except Exception:
    ..................................................
     self = <mengy_gdrive.GoogleDrive object at 0x7f126fcdf160>
     file_path = '[ETest.zip'
     remote_dir = ''
     chunksize = 8388608
     file_metadata = {'name': '[ETest.zip',
                      'parents': ['assea830sXQ8n44445', ]}
     file_name = '[ETest.zip'
     parent_id = 'assea830sXQ8n44445'
     media = <googleapiclient.http.MediaFileUpload object at 0x7f126e2d66
              a0>
     MediaFileUpload = <class 'googleapiclient.http.MediaFileUpload'>
     self.files_api.create = <method 'createMethod.<locals>.method' of <googleapiclient.d
                              iscovery.Resource object at 0x7f126fcdf400> discovery.py:750
                              >
    ..................................................

File /usr/local/lib/python3.6/dist-packages/googleapiclient/_helpers.py, line 134, in positional_wrapper
    116  def positional_wrapper(*args, **kwargs):
 (...)
    130          if positional_parameters_enforcement == POSITIONAL_EXCEPTION:
    131              raise TypeError(message)
    132          elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133              logger.warning(message)
--> 134      return wrapped(*args, **kwargs)
    ..................................................
     args = (<googleapiclient.http.HttpRequest object at 0x7f126f802080>
             , )
     kwargs = {}
     positional_parameters_enforcement = 'WARNING'
     POSITIONAL_EXCEPTION = 'EXCEPTION'
     POSITIONAL_WARNING = 'WARNING'
     logger.warning = <method 'Logger.warning' of <Logger googleapiclient._helpers
                        (WARNING)> __init__.py:1310>
     wrapped = <function 'HttpRequest.execute' http.py:845>
    ..................................................

File /usr/local/lib/python3.6/dist-packages/googleapiclient/http.py, line 871, in execute
    846  def execute(self, http=None, num_retries=0):
 (...)
    867
    868      if self.resumable:
    869          body = None
    870          while body is None:
--> 871              _, body = self.next_chunk(http=http, num_retries=num_retries)
    872          return body
    ..................................................
     self = <googleapiclient.http.HttpRequest object at 0x7f126f802080>
     http = <httplib2.Http object at 0x7f126fcdf1d0>
     num_retries = 0
     self.resumable = <googleapiclient.http.MediaFileUpload object at 0x7f126e2d66
                       a0>
     body = None
     self.next_chunk = <method 'HttpRequest.next_chunk' of <googleapiclient.http.Ht
                        tpRequest object at 0x7f126f802080> _helpers.py:115>
    ..................................................

File /usr/local/lib/python3.6/dist-packages/googleapiclient/_helpers.py, line 134, in positional_wrapper
    116  def positional_wrapper(*args, **kwargs):
 (...)
    130          if positional_parameters_enforcement == POSITIONAL_EXCEPTION:
    131              raise TypeError(message)
    132          elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133              logger.warning(message)
--> 134      return wrapped(*args, **kwargs)
    ..................................................
     args = (<googleapiclient.http.HttpRequest object at 0x7f126f802080>
             , )
     kwargs = {'http': <httplib2.Http object at 0x7f126fcdf1d0>,
               'num_retries': 0}
     positional_parameters_enforcement = 'WARNING'
     POSITIONAL_EXCEPTION = 'EXCEPTION'
     POSITIONAL_WARNING = 'WARNING'
     logger.warning = <method 'Logger.warning' of <Logger googleapiclient._helpers
                        (WARNING)> __init__.py:1310>
     wrapped = <function 'HttpRequest.next_chunk' http.py:922>
    ..................................................

File /usr/local/lib/python3.6/dist-packages/googleapiclient/http.py, line 1046, in next_chunk
    923  def next_chunk(self, http=None, num_retries=0):
 (...)
    1042              )
    1043
    1044          try:
    1045              resp, content = http.request(
--> 1046                  self.resumable_uri, method="PUT", body=data, headers=headers
    1047              )
    ..................................................
     self = <googleapiclient.http.HttpRequest object at 0x7f126f802080>
     http = <httplib2.Http object at 0x7f126fcdf1d0>
     num_retries = 0
     resp = Response
            {'content-type': 'text/plain; charset=utf-8',
             'x-guploader-uploadid': 'AAAAAAAAAAAAAA-7v4wbqsI
             BBBBBBBBBBBB-CCCCCCCCCCCCCCCC',
             'location': 'https://www.googleapis.com/upload/drive/v3/fil
             es?fields=%2A&supportsTeamDrives=true&alt=json&uploadType=re
             sumable&upload_id=AAAAAAAAAAAAAA-7v4wbqsI6PAdGsHO
             z1QztW-CCCCCCCCCCCCCCCC',
             'vary': 'Origin, X-Origin',
             'cache-control': 'no-cache, no-store, max-age=0, must-reval
             idat...
     content = b''
     http.request = <function 'wrap_http_for_auth.<locals>.new_request' transpor
                     t.py:153>
     self.resumable_uri = 'https://www.googleapis.com/upload/drive/v3/files?fields=%2A
                           &supportsTeamDrives=true&alt=json&uploadType=resumable&uploa
                           d_id=AAAAAAAAAAAAAA-7v4wbqsIBBBBBBBBBBBB-gIghi_
                           qmOrFGN_fULjHyLppiNX3wgXq6Cca7PEDyG8'
     data = <googleapiclient.http._StreamSlice object at 0x7f126f802048>
     headers = {'Content-Range': 'bytes 0-8388607/19220531',
                'Content-Length': '8388608'}
    ..................................................

File /usr/local/lib/python3.6/dist-packages/oauth2client/transport.py, line 175, in new_request
    153  def new_request(uri, method='GET', body=None, headers=None,
    154                  redirections=httplib2.DEFAULT_MAX_REDIRECTS,
    155                  connection_type=None):
 (...)
    171          body_stream_position = body.tell()
    172
    173      resp, content = request(orig_request_method, uri, method, body,
    174                              clean_headers(headers),
--> 175                              redirections, connection_type)
    176
    ..................................................
     uri = 'https://www.googleapis.com/upload/drive/v3/files?fields=%2A
            &supportsTeamDrives=true&alt=json&uploadType=resumable&uploa
            d_id=AAAAAAAAAAAAAA-7v4wbqsIBBBBBBBBBBBB-gIghi_
            qmOrFGN_fULjHyLppiNX3wgXq6Cca7PEDyG8'
     method = 'PUT'
     body = <googleapiclient.http._StreamSlice object at 0x7f126f802048>
     headers = {'Content-Range': 'bytes 0-8388607/19220531',
                'Content-Length': '8388608',
                'Authorization': 'Bearer ya29.asaaaaaaaaaaaaa
                rVYCUuH5qpewb-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                ssssssssssssssssssss-psrsSGhlV393lhdhMgyyNNib4AL1VBH25EWR0dA
                eeeeeeeeeeeeeeeeee'}
     redirections = 5
     httplib2.DEFAULT_MAX_REDIRECTS = 5
     connection_type = None
     body_stream_position = None
     body.tell = # AttributeError
          body = <googleapiclient.http._StreamSlice object at 0x7f126f
           802048>
     orig_request_method = <method 'Http.request' of <httplib2.Http object at 0x7f126fc
                            df1d0> __init__.py:1752>
    ..................................................

File /usr/local/lib/python3.6/dist-packages/oauth2client/transport.py, line 282, in request
    254  def request(http, uri, method='GET', body=None, headers=None,
    255              redirections=httplib2.DEFAULT_MAX_REDIRECTS,
    256              connection_type=None):
 (...)
    278      # NOTE: Allowing http or http.request is temporary (See Issue 601).
    279      http_callable = getattr(http, 'request', http)
    280      return http_callable(uri, method=method, body=body, headers=headers,
    281                           redirections=redirections,
--> 282                           connection_type=connection_type)
    ..................................................
     http = <method 'Http.request' of <httplib2.Http object at 0x7f126fc
             df1d0> __init__.py:1752>
     uri = 'https://www.googleapis.com/upload/drive/v3/files?fields=%2A
            &supportsTeamDrives=true&alt=json&uploadType=resumable&uploa
            d_id=AAAAAAAAAAAAAA-7v4wbqsIBBBBBBBBBBBB-gIghi_
            qmOrFGN_fULjHyLppiNX3wgXq6Cca7PEDyG8'
     method = 'PUT'
     body = <googleapiclient.http._StreamSlice object at 0x7f126f802048>
     headers = {b'Content-Range': b'bytes 0-8388607/19220531',
                b'Content-Length': b'8388608',
                b'Authorization': b'Bearer ya29.a0Ae4lvC2s7m_AWRJWW9eyKPQXS
                kJrVYCUuH5qpewb-0uQvTeBp81pBuFwNpVNajlCMhuVyAEeKEpbW8bteYPTS
                ffssssssssssssssssssss-psrsSGhlV393lhdhMgyyNNib4AL1VBH25EWR0
                dAeeeeeeeeeeeeeeeeee'}
     redirections = 5
     httplib2.DEFAULT_MAX_REDIRECTS = 5
     connection_type = None
     http_callable = <method 'Http.request' of <httplib2.Http object at 0x7f126fc
                      df1d0> __init__.py:1752>
    ..................................................

File /usr/local/lib/python3.6/dist-packages/httplib2/__init__.py, line 1991, in request
    1752  def request(
    1753      self,
    1754      uri,
    1755      method="GET",
    1756      body=None,
    1757      headers=None,
    1758      redirections=DEFAULT_MAX_REDIRECTS,
    1759      connection_type=None,
    1760  ):
 (...)
    1987                      method,
    1988                      body,
    1989                      headers,
    1990                      redirections,
--> 1991                      cachekey,
    1992                  )
    ..................................................
     self = <httplib2.Http object at 0x7f126fcdf1d0>
     uri = 'https://www.googleapis.com/upload/drive/v3/files?fields=%2A
            &supportsTeamDrives=true&alt=json&uploadType=resumable&uploa
            d_id=AAAAAAAAAAAAAA-7v4wbqsIBBBBBBBBBBBB-gIghi_
            qmOrFGN_fULjHyLppiNX3wgXq6Cca7PEDyG8'
     method = 'PUT'
     body = <googleapiclient.http._StreamSlice object at 0x7f126f802048>
     headers = {'content-range': 'bytes 0-8388607/19220531',
                'content-length': '8388608',
                'authorization': 'Bearer ya29.asaaaaaaaaaaaaa
                rVYCUuH5qpewb-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                ssssssssssssssssssss-psrsSGhlV393lhdhMgyyNNib4AL1VBH25EWR0dA
                eeeeeeeeeeeeeeeeee',
                'user-agent': 'Python-httplib2/0.17.3 (gzip)',
                'accept-encoding': 'gzip, deflate'}
     redirections = 5
     DEFAULT_MAX_REDIRECTS = 5
     connection_type = None
     cachekey = None
    ..................................................

File /usr/local/lib/python3.6/dist-packages/httplib2/__init__.py, line 1690, in _request
    1626  def _request(
    1627      self,
    1628      conn,
    1629      host,
    1630      absolute_uri,
    1631      request_uri,
    1632      method,
    1633      body,
    1634      headers,
    1635      redirections,
    1636      cachekey,
    1637  ):
 (...)
    1686                          _(
    1687                              "Redirected but the response is missing a Location: header."
    1688                          ),
    1689                          response,
--> 1690                          content,
    1691                      )
    ..................................................
     self = <httplib2.Http object at 0x7f126fcdf1d0>
     conn = <httplib2.HTTPSConnectionWithTimeout object at 0x7f12756ca8d
             0>
     host = 'www.googleapis.com'
     absolute_uri = 'https://www.googleapis.com/upload/drive/v3/files?fields=%2A
                     &supportsTeamDrives=true&alt=json&uploadType=resumable&uploa
                     d_id=AAAAAAAAAAAAAA-7v4wbqsIBBBBBBBBBBBB-gIghi_
                     qmOrFGN_fULjHyLppiNX3wgXq6Cca7PEDyG8'
     request_uri = '/upload/drive/v3/files?fields=%2A&supportsTeamDrives=true&a
                    lt=json&uploadType=resumable&upload_id=AAANsUltTVE6HLnImO36O
                    7mya-7v4wbqsIBBBBBBBBBBBB-sssssssssssssssssssssssssssssssssss
                    Cca7PEDyG8'
     method = 'PUT'
     body = <googleapiclient.http._StreamSlice object at 0x7f126f802048>
     headers = {'content-range': 'bytes 0-8388607/19220531',
                'content-length': '8388608',
                'authorization': 'Bearer ya29.asaaaaaaaaaaaaa
                rVYCUuH5qpewb-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                ssssssssssssssssssss-psrsSGhlV393lhdhMgyyNNib4AL1VBH25EWR0dA
                eeeeeeeeeeeeeeeeee',
                'user-agent': 'Python-httplib2/0.17.3 (gzip)',
                'accept-encoding': 'gzip, deflate'}
     redirections = 5
     cachekey = None
     _ = <function 'gettext' gettext.py:626>
     response = Response
                {'content-type': 'text/plain; charset=utf-8',
                 'x-guploader-uploadid': 'AAAAAAAAAAAAAA-7v4wbqsI
                 BBBBBBBBBBBB-CCCCCCCCCCCCCCCC',
                 'range': 'bytes=0-8388607',
                 'x-range-md5': '066f22139bba2254574c7c9a967eadddd',
                 'content-length': '0',
                 'date': 'Sat, 02 May 2020 15:31:12 GMT',
                 'server': 'UploadServer',
                 'alt-svc': 'h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2
                 592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000
                 ,h3-Q043=":443"; ma=2592000,qui...
     content = b''
    ..................................................

---- (full traceback above) ----
File /home/ming_gdrive.py, line 392, in upload
    result = self.files_api.create(body=file_metadata, media_body=media, fields="*", supportsTeamDrives=True).execute()
File /usr/local/lib/python3.6/dist-packages/googleapiclient/_helpers.py, line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
File /usr/local/lib/python3.6/dist-packages/googleapiclient/http.py, line 871, in execute
    _, body = self.next_chunk(http=http, num_retries=num_retries)
File /usr/local/lib/python3.6/dist-packages/googleapiclient/_helpers.py, line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
File /usr/local/lib/python3.6/dist-packages/googleapiclient/http.py, line 1046, in next_chunk
    self.resumable_uri, method="PUT", body=data, headers=headers
File /usr/local/lib/python3.6/dist-packages/oauth2client/transport.py, line 175, in new_request
    redirections, connection_type)
File /usr/local/lib/python3.6/dist-packages/oauth2client/transport.py, line 282, in request
    connection_type=connection_type)
File /usr/local/lib/python3.6/dist-packages/httplib2/__init__.py, line 1991, in request
    cachekey,
File /usr/local/lib/python3.6/dist-packages/httplib2/__init__.py, line 1690, in _request
    content,

RedirectMissingLocation: Redirected but the response is missing a Location: header.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label May 3, 2020
@busunkim96
Copy link
Contributor

This looks like #803. Can you double check the version of the google-api-python-client and httplib2?

How are you constructing the service object?

service = discovery.build(...)

@busunkim96 busunkim96 added needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels May 4, 2020
@busunkim96
Copy link
Contributor

Closing due to lack of activity.

@pkenjora
Copy link

This error is back: See b/165005527

@mengyyy
Copy link
Author

mengyyy commented Aug 23, 2020

Name: httplib2
Version: 0.18.1
Summary: A comprehensive HTTP client library.
Home-page: https://github.com/httplib2/httplib2
Author: Joe Gregorio
Author-email: joe@bitworking.org
License: MIT
Location: /usr/local/lib/python3.8/dist-packages

Version: 1.10.0
Summary: Google API Client Library for Python
Home-page: https://github.com/googleapis/google-api-python-client/
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: /usr/local/lib/python3.8/dist-packages

@joeysumi
Copy link

I'm experiencing this error again with the google-api-python-client:

  File "/gaia/.local/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/gaia/.local/lib/python3.6/site-packages/googleapiclient/http.py", line 846, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "/gaia/.local/lib/python3.6/site-packages/googleapiclient/http.py", line 164, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/gaia/.local/lib/python3.6/site-packages/google_auth_httplib2.py", line 198, in request
    uri, method, body=body, headers=request_headers, **kwargs)
  File "/gaia/.local/lib/python3.6/site-packages/httplib2/__init__.py", line 1976, in request
    cachekey,
  File "/gaia/.local/lib/python3.6/site-packages/httplib2/__init__.py", line 1679, in _request
    content,
httplib2.RedirectMissingLocation: Redirected but the response is missing a Location: header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

5 participants