requests.exceptions.HTTPError not handled by praw
See original GitHub issueDescribe the Bug
When I was using submit_image
, praw encountered a 500 internal server error.
I have a handler for praw.exceptions.RedditAPIException
, but that did not get caught because a requests.exceptions.HTTPError
was raised instead of a praw.exceptions.RedditAPIException
.
I assume that the intent is to have praw except exceptions from “requests” and raise them as praw exceptions (to avoid clients depending on knowledge of internal design).
$ python3 -m pip freeze | grep -e requests -e praw
praw==7.5.0
prawcore==2.3.0
requests==2.26.0
requests-file==1.4.3
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
requests-unixsocket==0.2.0
Desired Result
praw should have raised a praw.exceptions.RedditAPIException
(or one of the classes that inherit from that)
Relevant Logs
File "/home/rolf/weather/redditSend.py", line 160, in postImage
submission = sub.submit_image(
File "/home/rolf/.local/lib/python3.8/site-packages/praw/models/reddit/subreddit.py", line 1188, in submit_image
"title": title,
File "/home/rolf/.local/lib/python3.8/site-packages/praw/models/reddit/subreddit.py", line 701, in _upload_media
response.raise_for_status()
File "/home/rolf/.local/lib/python3.8/site-packages/requests/models.py", line 953, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://reddit-uploaded-media.s3-accelerate.amazonaws.com/
Code to reproduce the bug
# I don't have a reproduction because in requires reddit to send back a 500.
My code example does not include the Reddit()
initialization to prevent credential leakage.
Yes
This code has previously worked as intended.
No
Operating System/Environment
Linux Mint 20.2 Cinnamon
Python Version
Python 3.8.10
PRAW Version
7.5.0
Prawcore Version
2.3.0
Anything else?
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
PRAW and HTTPError handling : r/redditdev
I get error like these, which kills the thread and then sends me email of the error dumps. raise HTTPError(http_error_msg, response=self) requests.exceptions.
Read more >Exceptions — PRAW 3.6.2 documentation - Read the Docs
This page documents the exceptions that can occur while running PRAW and what they mean. The exceptions can be divided into three rough...
Read more >How to use the requests.exceptions.HTTPError function ... - Snyk
To help you get started, we've selected a few requests.exceptions.HTTPError examples ... and handle automatically raise HTTPError(e, request_object.text).
Read more >python - PRAW: get_submission works inconsistently - Stack Overflow
The script gets the information from a specific comment on Reddit. It will work or not depending on the permalink given to it....
Read more >Python Reddit API Wrapper Documentation - Read the Docs
(not PRAW) we might not get all the things, but more about that later. ... [BUGFIX] Don't cache requests whose responses will result...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the pointer. I was able to get something working, but I have to say that writing the test was about 100 times harder than writing the actual code. Anyway, I’m just waiting for someone to start the tests on my latest commit.
Sounds good! Would you like some help? If so, feel free to open a PR and I can take a look.