簡體   English   中英

tweepy 和 google colab 有錯誤

[英]There is error in tweepy and google colab

這是錯誤

ValueError Traceback(最近一次調用最后一次)

/usr/local/lib/python3.6/dist-packages/tweepy/auth.py in _get_request_token(self, access_type)
     65                 url += '?x_auth_access_type=%s' % access_type
---> 66             return self.oauth.fetch_request_token(url)
     67         except Exception as e:

17幀

/usr/local/lib/python3.6/dist-packages/requests_oauthlib/oauth1_session.py in fetch_request_token(self, url, realm, **request_kwargs)
    286         self._client.client.realm = " ".join(realm) if realm else None
--> 287         token = self._fetch_token(url, **request_kwargs)
    288         log.debug("Resetting callback_uri and realm (not needed in next phase).")

/usr/local/lib/python3.6/dist-packages/requests_oauthlib/oauth1_session.py in _fetch_token(self, url, **request_kwargs)
    364         log.debug("Fetching token from %s using client %s", url, self._client.client)
--> 365         r = self.post(url, **request_kwargs)
    366 

/usr/local/lib/python3.6/dist-packages/requests/sessions.py in post(self, url, data, json, **kwargs)
    577 
--> 578         return self.request('POST', url, data=data, json=json, **kwargs)
    579 

/usr/local/lib/python3.6/dist-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    515         )
--> 516         prep = self.prepare_request(req)
    517 

/usr/local/lib/python3.6/dist-packages/requests/sessions.py in prepare_request(self, request)
    458             cookies=merged_cookies,
--> 459             hooks=merge_hooks(request.hooks, self.hooks),
    460         )

/usr/local/lib/python3.6/dist-packages/requests/models.py in prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
    317         self.prepare_body(data, files, json)
--> 318         self.prepare_auth(auth, url)
    319 

/usr/local/lib/python3.6/dist-packages/requests/models.py in prepare_auth(self, auth, url)
    548             # Allow auth to make its changes.
--> 549             r = auth(self)
    550 

/usr/local/lib/python3.6/dist-packages/requests_oauthlib/oauth1_auth.py in __call__(self, r)
    108             r.url, headers, _ = self.client.sign(
--> 109                 unicode(r.url), unicode(r.method), None, r.headers
    110             )

/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/__init__.py in sign(self, uri, http_method, body, headers, realm)
    312         request.oauth_params.append(
--> 313             ('oauth_signature', self.get_oauth_signature(request)))
    314 

/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/__init__.py in get_oauth_signature(self, request)
    126 
--> 127         uri, headers, body = self._render(request)
    128 

/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/__init__.py in _render(self, request, formencode, realm)
    209             headers = parameters.prepare_headers(
--> 210                 request.oauth_params, request.headers, realm=realm)
    211         elif self.signature_type == SIGNATURE_TYPE_BODY and request.decoded_body is not None:

/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/utils.py in wrapper(params, *args, **kwargs)
     31         params = filter_oauth_params(params)
---> 32         return target(params, *args, **kwargs)
     33 

/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/parameters.py in prepare_headers(oauth_params, headers, realm)
     58         escaped_name = utils.escape(oauth_parameter_name)
---> 59         escaped_value = utils.escape(value)
     60 

/usr/local/lib/python3.6/dist-packages/oauthlib/oauth1/rfc5849/utils.py in escape(u)
     56         raise ValueError('Only unicode objects are escapable. ' +
---> 57                          'Got %r of type %s.' % (u, type(u)))
     58     # Letters, digits, and the characters '_.-' are already treated as safe

ValueError:只有 unicode 對象是可轉義的。 在 <class 'generator'> 類型的 0x7f1a83f1cf68> 處得到 <generator object to_unicode..。

During handling of the above exception, another exception occurred:

TweepError                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tweepy/auth.py in get_authorization_url(self, signin_with_twitter, access_type)
     84                 url = self._get_oauth_url('authorize')
---> 85             self.request_token = self._get_request_token(access_type=access_type)
     86             return self.oauth.authorization_url(url)

/usr/local/lib/python3.6/dist-packages/tweepy/auth.py in _get_request_token(self, access_type)
     67         except Exception as e:
---> 68             raise TweepError(e)
     69 

TweepError: Only unicode objects are escapable. Got <generator object to_unicode.<locals>.<genexpr> at 0x7f1a83f1cf68> of type <class 'generator'>.

During handling of the above exception, another exception occurred:

TweepError                                Traceback (most recent call last)
<ipython-input-8-0d2d0c4ff837> in <module>()
      1 auth = tweepy.OAuthHandler(a ,apis ,callbackurl)
----> 2 redirecurl = auth.get_authorization_url()
      3 print(redirecurl)

/usr/local/lib/python3.6/dist-packages/tweepy/auth.py in get_authorization_url(self, signin_with_twitter, access_type)
     86             return self.oauth.authorization_url(url)
     87         except Exception as e:
---> 88             raise TweepError(e)
     89 
     90     def get_access_token(self, verifier=None):

TweepError: Only unicode objects are escapable. Got <generator object to_unicode.<locals>.<genexpr> at 0x7f1a83f1cf68> of type <class 'generator'>.

這是代碼

我使用谷歌 colab 所以我包括這個

!pip install tweepy

這一切都不是真的我已經修改了它

a = ["uAtzGszfcP0J1jTebtkjrgntuhvbnkuteghvk,erhnfoqi2j1289747865432565BGzfBjrjAAAAAAA"]

apis = ["rabefnO5bypwuV5KTcuS766ncZs8ctrNtrh6pJfMwDFvrwuHprtgjivruiohgbtvuhrgyuvydgfugdryehfguirdjbvyurgfy"]

b = ["AAAAAAAAAAAAAAAAAgregregergrehyrjrtksjgnyrfuykrguyrthviurjgoierghfuywehnidf3yiueghf6yregAAAAAAAAAAAL5AKgEAAAAA3wLIE6HWAXgMPcTZ8L9t1K9Lu1I%3D6SpRSXAtJF248GnzzdJ79BSyoaDMFqfPTFe8rKnxjgm5eMCQxs"]

at = ["1333671816829rehtrTNTYGBILTEJMNGUNIOERHNGVKJRHFUKERGJNVIUDFHV.NTOBN;GUONTLR8908329407837645669377-SUFHAAynfZh8DeSx3w4yVveKm5D5Ct"]

As = ["7wYChDbdN36sGf2FJSCWBEMqk65x1I7nJ4k3B#GHKJKDVHNHIUERKNVJI.UY%$VDJKRGVNEK,FVNUIDRVBKDGUH ,KER JVKUDFHBKREJVBYDIGBGKERUFVHBKJFBRKJCNzkOmfrLA"]

導入 tweepy,google,time

import tweepy
import webbrowser
import time

這也不是真的

callbackurl = 'oob' # https://cybemchi.000webhostapp.com/
auth = tweepy.OAuthHandler(a ,apis ,callbackurl)
redirecurl = auth.get_authorization_url()
print(redirecurl)

問題是因為您將其保留為列表

a = [ "uAtz...." ] 
apis = [ "rabefn..." ]

但它應該是直接字符串

a = "uAtz...." 
apis = "rabefn..."

tweepy.OAuthHandler( a, apis, ...)

或者你應該使用 index [0]從列表中獲取字符串

a = [ "uAtz...." ] 
apis = [ "rabefn..." ]

tweepy.OAuthHandler( a[0], apis[0], ... )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM