Tweepy:Twitter 错误响应:状态代码 = 403:对 Azure 解决方案笔记本 (Spark) 中的推文提取进行故障排除

问题描述 投票:0回答:1

我在使用 Tweepy v3.10.0 和 Twitter API 提取推文时遇到 403 错误。搜索 API 在 Postman 中工作正常,表明笔记本Ingest_Process_Tweets 中存在身份验证问题。这是我执行的管道:Pipeline和对应的笔记本:Ingest_Process_Tweets。 完整错误如下: Py4JJavaError:调用 o2907.throwExceptionIfHave 时发生错误。 : com.microsoft.spark.notebook.msutils.NotebookExecutionException:Twitter 错误响应:状态代码 = 403

我非常感谢任何解决此问题的帮助或指导。

我已经尝试使用 Twitter 的 Postman Collection 进行搜索 API,效果很好。

pyspark twitter tweepy azure-synapse twitterapi-python
1个回答
0
投票

从今天早上开始我就面临这个问题。我尝试了几种方法,但结果仍然相同,我总是遇到相同的错误:

recent call last)<ipython-input-11-988e88e9cba4> in <module> 48 at=dt2.strftime("%m/%d/%Y, %H:%M:%S %Z") 49 ---> 50 paginator = client.search_recent_tweets(query=query, tweet_fields=["lang", "context_annotations", "public_metrics", "created_at", "id", "text", "author_id", "entities", "geo"], max_results=maxtweets_persearch) 51 52 for page in paginator.flatten(): ~/cluster-env/env/lib/python3.6/site-packages/tweepy/client.py in search_recent_tweets(self, query, user_auth, **params) 655 "since_id", "start_time", "tweet.fields", "until_id", 656 "user.fields" --> 657 ), data_type=Tweet, user_auth=user_auth 658 ) 659 ~/cluster-env/env/lib/python3.6/site-packages/tweepy/client.py in _make_request(self, method, route, params, endpoint_parameters, json, data_type, user_auth) 174 if data_type is not None: 175 if isinstance(data, list): --> 176 data = [data_type(result) for result in data] 177 elif data is not None: 178 data = data_type(data) ~/cluster-env/env/lib/python3.6/site-packages/tweepy/client.py in <listcomp>(.0) 174 if data_type is not None: 175 if isinstance(data, list): --> 176 data = [data_type(result) for result in data] 177 elif data is not None: 178 data = data_type(data) ~/cluster-env/env/lib/python3.6/site-packages/tweepy/tweet.py in __init__(self, data) 39 if self.created_at is not None: 40 self.created_at = datetime.datetime.strptime( ---> 41 self.created_at, "%Y-%m-%dT%H:%M:%S.%f%z" 42 ) 43 ~/cluster-env/env/lib/python3.6/_strptime.py in _strptime_datetime(cls, data_string, format) 563 """Return a class cls instance based on the input string and the 564 format string.""" --> 565 tt, fraction = _strptime(data_string, format) 566 tzname, gmtoff = tt[-2:] 567 args = tt[:6] + (fraction,) ~/cluster-env/env/lib/python3.6/_strptime.py in _strptime(data_string, format) 360 if not found: 361 raise ValueError("time data %r does not match format %r" % --> 362 (data_string, format)) 363 if len(data_string) != found.end(): 364 raise ValueError("unconverted data remains: %s" % ValueError: time data '2024-05-03T17:13:39.000Z' does not match format '%Y-%m-%dT%H:%M:%S.%f%z' 
生成此错误的代码位于:我的代码

我尝试了几种日期转换方法,但它总是给出相同的结果,就好像代码没有考虑我的更新一样。请问有人可以帮我解决这个问题吗?

© www.soinside.com 2019 - 2024. All rights reserved.