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

If json.loads fails, carry on without raising an exception. Fixes #298 #299

Merged
merged 1 commit into from
Jul 21, 2015

Conversation

jessamynsmith
Copy link
Contributor

Here is a possible refactoring to allow the library to carry on if json.loads fails.
(Note: I am not sure how to reproduce the error, so I haven't been able to test this yet. I have tested that posting works.)
Fixes #298

RouxRC added a commit that referenced this pull request Jul 21, 2015
If json.loads fails, carry on without raising an exception. Fixes #298
@RouxRC RouxRC merged commit ef0e9f0 into python-twitter-tools:master Jul 21, 2015
@RouxRC
Copy link
Member

RouxRC commented Jul 21, 2015

seems all good to me! thanks!

@plouj
Copy link

plouj commented Jul 21, 2015

FYI: The original problem can be reproduced with bad auth. Eg:

from twitter.stream import TwitterStream
from twitter.oauth import OAuth

if __name__ == '__main__':
    auth = OAuth(
        consumer_key='bad-key',
    consumer_secret='bad-secret',
    token='bad-token',
    token_secret='bad-secret')
    stream = TwitterStream(auth=auth,
                           domain='userstream.twitter.com',
                           timeout=0,
                           block=True,
                           heartbeat_timeout=90)
    query_args = dict()
    query_args['track'] = "puppy"
    tweet_iter = stream.user(**query_args)
    for tweet in tweet_iter:
        pass

@RouxRC
Copy link
Member

RouxRC commented Jul 21, 2015

good and useful catch thanks!
FYI, when crashtesting the stream, I disconnected occasionally my RJ45 cable to test the impact :)

@jessamynsmith
Copy link
Contributor Author

Ah, thank you! I actually get a slightly different error when I do that (perhaps it's a python version thing?) but I do get an error. In my own usage of the twitter library I was doing something a little different, so I didn't see any error at all even with bad credentials. I can confirm that the new version exhibits different behavior:
twitter.api.TwitterHTTPError: Twitter sent status 401 for URL:...

@Floby
Copy link

Floby commented Jul 28, 2015

Thank you for this.
Any idea when we should expect this to be published on pypi ?

@sixohsix
Copy link
Collaborator

@Floby I just published this to PyPI, in version 1.17.1.

@Floby
Copy link

Floby commented Jul 28, 2015

my failing prod and I thank you =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants