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

Why is the datetime format of the api response not the same as specified in the given format? #1857

Closed
c1910475054 opened this issue Apr 4, 2022 · 4 comments
Labels
Invalid This is not valid Question This is a question

Comments

@c1910475054
Copy link

ValueError: time data '2022-04-01T23:53:21.000Z' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'

So the response does not match the given format, is this piece of code of utils.py outdated? Or has this issue already been solved?

Thanks in advance

Following issue occurs when requesting tweets in a specific timeframe

<ipython-input-76-51d491f82013> in <module>
      9 end_time = '2022-04-02T00:00:00Z'
     10 
---> 11 tweets_v2 = client.search_recent_tweets(query=query, tweet_fields=['context_annotations', 'created_at'], start_time=start_time, end_time=end_time, max_results=10)
     12 
     13 for tweet_v2 in tweets_v2.data:

~\anaconda3\envs\gpu\lib\site-packages\tweepy\client.py in search_recent_tweets(self, query, user_auth, **params)
   1253                 "since_id", "sort_order", "start_time", "tweet.fields",
   1254                 "until_id", "user.fields"
-> 1255             ), data_type=Tweet, user_auth=user_auth
   1256         )
   1257 

~\anaconda3\envs\gpu\lib\site-packages\tweepy\client.py in _make_request(self, method, route, params, endpoint_parameters, json, data_type, user_auth)
    136 
    137         data = response.get("data")
--> 138         data = self._process_data(data, data_type=data_type)
    139 
    140         includes = response.get("includes", {})

~\anaconda3\envs\gpu\lib\site-packages\tweepy\client.py in _process_data(self, data, data_type)
    149         if data_type is not None:
    150             if isinstance(data, list):
--> 151                 data = [data_type(result) for result in data]
    152             elif data is not None:
    153                 data = data_type(data)

~\anaconda3\envs\gpu\lib\site-packages\tweepy\client.py in <listcomp>(.0)
    149         if data_type is not None:
    150             if isinstance(data, list):
--> 151                 data = [data_type(result) for result in data]
    152             elif data is not None:
    153                 data = data_type(data)

~\anaconda3\envs\gpu\lib\site-packages\tweepy\tweet.py in __init__(self, data)
    128         self.created_at = data.get("created_at")
    129         if self.created_at is not None:
--> 130             self.created_at = parse_datetime(self.created_at)
    131 
    132         self.entities = data.get("entities")

~\anaconda3\envs\gpu\lib\site-packages\tweepy\utils.py in parse_datetime(datetime_string)
     13 def parse_datetime(datetime_string):
     14     return datetime.datetime.strptime(
---> 15         datetime_string, "%Y-%m-%dT%H:%M:%S.%f%z"
     16     ).replace(tzinfo=datetime.timezone.utc)

~\anaconda3\envs\gpu\lib\_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,)

~\anaconda3\envs\gpu\lib\_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" %
@Harmon758
Copy link
Member

What versions of Python and Tweepy are you using?

@Harmon758 Harmon758 added Need Follow-Up This needs to be followed up on to be actionable Question This is a question labels Apr 4, 2022
@c1910475054
Copy link
Author

Tweepy 4.8.0
Python 3.8.5

@Harmon758
Copy link
Member

I'm unable to reproduce this with Python 3.8.
Can you provide a reproducible example (MCVE/SSCCE)?

@Harmon758 Harmon758 added the No Reproduction This is not reproducible label Apr 5, 2022
@c1910475054
Copy link
Author

It was due to the python version, apparently running on a wrong environment with python 3.6

@Harmon758 Harmon758 added Invalid This is not valid and removed Need Follow-Up This needs to be followed up on to be actionable No Reproduction This is not reproducible labels Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid This is not valid Question This is a question
Projects
None yet
Development

No branches or pull requests

2 participants