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

403 Error because tweets are too long #21

Open
fakebenjay opened this issue Feb 1, 2019 · 9 comments
Open

403 Error because tweets are too long #21

fakebenjay opened this issue Feb 1, 2019 · 9 comments

Comments

@fakebenjay
Copy link

Hey,
I've been running the trackthenews script and when it encounters an article title that's too long, it returns a 403 error:

Traceback (most recent call last):
  File "/home/ubuntu/.pyenv/versions/3.6.5/bin/trackthenews", line 11, in <module>
    sys.exit(main())
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/trackthenews/core.py", line 441, in main
    article.tweet()
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/trackthenews/core.py", line 115, in tweet
    twitter.update_status(status=status, media_ids=media_ids)
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/twython/endpoints.py", line 114, in update_status
    return self.post('statuses/update', params=params)
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/twython/api.py", line 268, in post
    return self.request(endpoint, 'POST', params=params, version=version)
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/twython/api.py", line 258, in request
    api_call=url)
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/twython/api.py", line 194, in _request
    retry_after=response.headers.get('X-Rate-Limit-Reset'))
twython.exceptions.TwythonError: Twitter API returned a 403 (Forbidden), Tweet needs to be a bit shorter.

Is there a workaround for this?

@thisisparker
Copy link
Contributor

Hm, no, I hadn't run into that! It's easy enough to truncate (probably with a ) which I should include in a new version. Out of curiosity, what story has such a long title?

@fakebenjay
Copy link
Author

I lost the exact title, but it was a long FDA announcement about some technical drug-related thing. Very dense and dry gov't agency stuff.

@fakebenjay
Copy link
Author

Also, while I'm on this issue, I've also gotten a KeyError: title traceback error. Any idea what that might be?

Traceback (most recent call last):
  File "/home/ubuntu/.pyenv/versions/3.6.5/bin/trackthenews", line 11, in <module>
    sys.exit(main())
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/trackthenews/core.py", line 420, in main
    articles = parse_feed(outlet, url, delicate, redirects)
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/trackthenews/core.py", line 185, in parse_feed
    title = entry['title']
  File "/home/ubuntu/.pyenv/versions/3.6.5/lib/python3.6/site-packages/feedparser.py", line 356, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'title'

@thisisparker
Copy link
Contributor

Huh, that would happen if an RSS feed entry doesn't have the (required) title field, probably. It doesn't happen much (I haven't seen it in the wild!) but I guess people put all kinds of RSS feeds out there, huh? This should probably fail a little more gracefully, though! Thanks for the report!

@fakebenjay
Copy link
Author

Thank you! Will try running without that problem feed temporarily...

@fakebenjay
Copy link
Author

Just a heads up about that KeyError, this is the problem feed: https://www.michigan.gov/rss/0,2348,7-154-11472--53088-,00.xml

In theory, I'd imagine you wouldn't want the entire program to crap out because of one faulty article. Is there a way to make it continue, even if one blog post was untweetable?

@thisisparker
Copy link
Contributor

Yes, and honestly it should probably tweet without a title just as it does without an outlet. I'll plan to fix that, thank you!

@matthewmcvickar
Copy link
Contributor

I've submitted a PR that I think addresses this: #22

@matthewmcvickar
Copy link
Contributor

And another that addresses potentially empty title/URL: #23

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

No branches or pull requests

3 participants