praw: Praw submit_image/submit_video with websockets failing as of 3:06 pm Central on Sep. 29, 2023
Describe the Bug
Starting about 33 minutes ago the Praw submit_image and submit_video methods began failing with the error message ConnectionRefusedError: [Errno 111] Connection refused when submitting image and video posts using websockets. without_websockets=True does seem to work, but notably does not return a submission object, which means callers do not receive the newly created submission or submission ID.
I’m not sure if this is an intentional change by Reddit or not, as this is an undocumented API and they likely won’t announce changes to it either way.
Desired Result
Image and video posts should submit with websockets.
Code to reproduce the bug
reddit.subreddit(subreddit).submit_image(title='My title', timeout=30, image_path='/tmp/image.png')
The Reddit() initialization in my code example does not include the following parameters to prevent credential leakage:
client_secret, password, or refresh_token.
- Yes
Relevant Logs
Traceback (most recent call last):
File "/var/task/praw/models/reddit/subreddit.py", line 613, in _submit_media
connection = websocket.create_connection(websocket_url, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/websocket/_core.py", line 610, in create_connection
websock.connect(url, **options)
File "/var/task/websocket/_core.py", line 251, in connect
self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/websocket/_http.py", line 129, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/websocket/_http.py", line 204, in _open_socket
raise err
File "/var/task/websocket/_http.py", line 184, in _open_socket
sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/task/apps/reddit/bot.py", line 285, in submit_post
reddit_submission = subreddit.submit_image(**submission_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/praw/util/deprecate_args.py", line 43, in wrapped
return func(**dict(zip(_old_args, args)), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/task/praw/models/reddit/subreddit.py", line 1263, in submit_image
return self._submit_media(
^^^^^^^^^^^^^^^^^^^
File "/var/task/praw/models/reddit/subreddit.py", line 619, in _submit_media
raise WebSocketException(
praw.exceptions.WebSocketException: Error establishing websocket connection.
This code has previously worked as intended.
Yes
Operating System/Environment
Linux
Python Version
3.11
PRAW Version
7.6.0
Prawcore Version
2.3.0
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 27 (10 by maintainers)
Yep, working on a fix for that right now!
I did a clean install from scratch. It worked perfectly ! PS: On my first run, I got the error “websocket error occurred, it may still have been created, please check”, but on my second run, it succeeded without entering the except block.
Currently looking but so far it seems that if the websocket fails or you tell PRAW to not use websockets, PRAW won’t be able to return a submission object because there isn’t anything in the responses that returns the new submission ID.
Gotcha. Then I’ll need to do some more changes to it.