korakot / kora

Convenient tools for Colab
MIT License
270 stars 38 forks source link

RedirectMissingLocation: Redirected but the response is missing a Location: header while using upload_public #9

Closed naveennamani closed 3 years ago

naveennamani commented 3 years ago

When I'm trying to upload file to the gdrive, I'm getting the following error.

---------------------------------------------------------------------------
RedirectMissingLocation                   Traceback (most recent call last)
<ipython-input-12-5fac1a3d773d> in <module>()
----> 1 url = upload_public("video.mp4")

11 frames
/usr/local/lib/python3.6/dist-packages/kora/drive.py in upload_public(filename)
     41     f = get_file(basename(filename))
     42     f.SetContentFile(filename)
---> 43     f.Upload()
     44     f.InsertPermission({'type': 'anyone', 'value': 'anyone', 'role': 'reader'})
     45     return 'https://drive.google.com/uc?id=' + f.get('id')  # direct link

/usr/local/lib/python3.6/dist-packages/pydrive/files.py in Upload(self, param)
    283         self._FilesPatch(param=param)
    284     else:
--> 285       self._FilesInsert(param=param)
    286 
    287   def Trash(self, param=None):

/usr/local/lib/python3.6/dist-packages/pydrive/auth.py in _decorated(self, *args, **kwargs)
     73       self.http = self.auth.Get_Http_Object()
     74 
---> 75     return decoratee(self, *args, **kwargs)
     76   return _decorated
     77 

/usr/local/lib/python3.6/dist-packages/pydrive/files.py in _FilesInsert(self, param)
    367         param['media_body'] = self._BuildMediaBody()
    368       metadata = self.auth.service.files().insert(**param).execute(
--> 369         http=self.http)
    370     except errors.HttpError as error:
    371       raise ApiRequestError(error)

/usr/local/lib/python3.6/dist-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

/usr/local/lib/python3.6/dist-packages/googleapiclient/http.py in execute(self, http, num_retries)
    860             body = None
    861             while body is None:
--> 862                 _, body = self.next_chunk(http=http, num_retries=num_retries)
    863             return body
    864 

/usr/local/lib/python3.6/dist-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    132                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 
    136         return positional_wrapper

/usr/local/lib/python3.6/dist-packages/googleapiclient/http.py in next_chunk(self, http, num_retries)
   1035             try:
   1036                 resp, content = http.request(
-> 1037                     self.resumable_uri, method="PUT", body=data, headers=headers
   1038                 )
   1039             except:

/usr/local/lib/python3.6/dist-packages/oauth2client/transport.py in new_request(uri, method, body, headers, redirections, connection_type)
    173         resp, content = request(orig_request_method, uri, method, body,
    174                                 clean_headers(headers),
--> 175                                 redirections, connection_type)
    176 
    177         # A stored token may expire between the time it is retrieved and

/usr/local/lib/python3.6/dist-packages/oauth2client/transport.py in request(http, uri, method, body, headers, redirections, connection_type)
    280     return http_callable(uri, method=method, body=body, headers=headers,
    281                          redirections=redirections,
--> 282                          connection_type=connection_type)
    283 
    284 

/usr/local/lib/python3.6/dist-packages/httplib2/__init__.py in request(self, uri, method, body, headers, redirections, connection_type)
   1989                         headers,
   1990                         redirections,
-> 1991                         cachekey,
   1992                     )
   1993         except Exception as e:

/usr/local/lib/python3.6/dist-packages/httplib2/__init__.py in _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey)
   1688                             ),
   1689                             response,
-> 1690                             content,
   1691                         )
   1692                     # Fix-up relative redirects (which violate an RFC 2616 MUST)

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

Is it due to pydrive error? Or am I missing something?

naveennamani commented 3 years ago

It's solved by installing httplib2==0.15.0 as discussed in this answer https://stackoverflow.com/a/60651792/5659132