Соединение с Google Spreadhseet с использованием python 3 - PullRequest
0 голосов
/ 22 марта 2020

Я использую следующий код для подключения к электронной таблице Google.

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scope)

gc = gspread.authorize(credentials)

и у меня есть учетные данные. json, которые я экспортировал из консоли API Google Sheets.

Но я получаю следующую ошибку:

TypeError: cannot use a string pattern on a bytes-like object

Это полный след ошибки:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-ee731769ce7a> in <module>()
      7 credentials = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scope)
      8 
----> 9 gc = gspread.authorize(credentials)

~\Anaconda3\lib\site-packages\gspread\__init__.py in authorize(credentials, client_class)
     36     """
     37     client = client_class(auth=credentials)
---> 38     client.login()
     39     return client

~\Anaconda3\lib\site-packages\gspread\client.py in login(self)
     49 
     50             http = httplib2.Http()
---> 51             self.auth.refresh(http)
     52 
     53         self.session.headers.update({

c:\users\developer\appdata\local\google\cloud sdk\google-cloud-sdk\lib\third_party\oauth2client\client.py in refresh(self, http)
    570                   request.
    571         """
--> 572         self._refresh(http.request)
    573 
    574     def revoke(self, http):

c:\users\developer\appdata\local\google\cloud sdk\google-cloud-sdk\lib\third_party\oauth2client\client.py in _refresh(self, http_request)
    780         """
    781         if not self.store:
--> 782             self._do_refresh_request(http_request)
    783         else:
    784             self.store.acquire_lock()

c:\users\developer\appdata\local\google\cloud sdk\google-cloud-sdk\lib\third_party\oauth2client\client.py in _do_refresh_request(self, http_request, attempt)
    816         resp, content = http_request(
    817             self.token_uri.encode('idna'), method='POST',
--> 818             body=body, headers=headers)
    819         content = _helpers._from_bytes(content)
    820         if resp.status == http_client.OK:

c:\users\developer\appdata\local\google\cloud sdk\google-cloud-sdk\lib\third_party\httplib2\python3\httplib2\__init__.py in request(self, uri, method, body, headers, redirections, connection_type)
   1767             uri = iri2uri(uri)
   1768 
-> 1769             (scheme, authority, request_uri, defrag_uri) = urlnorm(uri)
   1770 
   1771             conn_key = scheme + ":" + authority

c:\users\developer\appdata\local\google\cloud sdk\google-cloud-sdk\lib\third_party\httplib2\python3\httplib2\__init__.py in urlnorm(uri)
    218 
    219 def urlnorm(uri):
--> 220     (scheme, authority, path, query, fragment) = parse_uri(uri)
    221     if not scheme or not authority:
    222         raise RelativeURIError("Only absolute URIs are allowed. uri = %s" % uri)

c:\users\developer\appdata\local\google\cloud sdk\google-cloud-sdk\lib\third_party\httplib2\python3\httplib2\__init__.py in parse_uri(uri)
    213         (scheme, authority, path, query, fragment) = parse_uri(uri)
    214     """
--> 215     groups = URI.match(uri).groups()
    216     return (groups[1], groups[3], groups[4], groups[6], groups[8])
    217 

TypeError: cannot use a string pattern on a bytes-like object
...