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

PRAW unable to handle x-ratelimit-remaining header #173

Closed
1 task done
dkozinn opened this issue Dec 13, 2023 · 11 comments
Closed
1 task done

PRAW unable to handle x-ratelimit-remaining header #173

dkozinn opened this issue Dec 13, 2023 · 11 comments
Labels

Comments

@dkozinn
Copy link

dkozinn commented Dec 13, 2023

Describe the Bug

Calls to subreddit.mod.stream.modqueue are failing with error message similar to this:

File "/home/ubuntu/src/src/prawcore/prawcore/rate_limit.py", line 79, in update
    self.remaining = float(response_headers["x-ratelimit-remaining"])
ValueError: could not convert string to float: '991, 98'

Desired Result

Ratelimit handling works without errors.

Code to reproduce the bug

#!/usr/bin/python3

import praw

SUB = "nasa"

def main():
    """Main loop"""

    reddit = praw.Reddit("nasamodqbot")
    subreddit = reddit.subreddit(SUB)

    for submission in subreddit.mod.stream.modqueue():
        print("Made it here")

if __name__ == "__main__":
    main()

My code does not include sensitive credentials

  • Yes, I have removed sensitive credentials from my code.

Relevant Logs

Exception has occurred: ValueError
could not convert string to float: '962, 99'
  File "/home/david/src/r-nasabot/src/test99.py", line 16, in main
    for submission in subreddit.mod.stream.modqueue():
  File "/home/david/src/r-nasabot/src/test99.py", line 20, in <module>
    main()
ValueError: could not convert string to float: '962, 99'

This code has previously worked as intended

Yes

Operating System/Environment

Ubuntu 20.04, 22.04

Python Version

3.8.10, 3.10.12

prawcore Version

2.3.0

Links, references, and/or additional comments?

No response

@dkozinn dkozinn added the bug label Dec 13, 2023
@dkozinn
Copy link
Author

dkozinn commented Dec 13, 2023

Update: As of 21:00 UTC the issue seems to be resolved. The sample code will no longer reproduce the error at this time.

@snarfed
Copy link

snarfed commented Dec 14, 2023

My guess is that this was a transient bug on Reddit's part, since their docs on https://support.reddithelp.com/hc/en-us/articles/16160319875092-Reddit-Data-API-Wiki say that this header value is a single number:

X-Ratelimit-Remaining: Approximate number of requests left to use

Regardless, ideally prawcore should just ignore bad header values here, not crash.

@oussama-gourari
Copy link

Kept getting this today at around 14:35 UTC:

ValueError: could not convert string to float: '544.0, 944'
ValueError: could not convert string to float: '543.0, 943'
ValueError: could not convert string to float: '542.0, 942'
ValueError: could not convert string to float: '540.0, 940'
ValueError: could not convert string to float: '539.0, 939'
ValueError: could not convert string to float: '537.0, 937'
ValueError: could not convert string to float: '536.0, 936'
ValueError: could not convert string to float: '534.0, 934'
ValueError: could not convert string to float: '533.0, 933'
ValueError: could not convert string to float: '531.0, 931'
ValueError: could not convert string to float: '530.0, 930'
ValueError: could not convert string to float: '529.0, 929'
ValueError: could not convert string to float: '528.0, 928'
ValueError: could not convert string to float: '527.0, 927'
ValueError: could not convert string to float: '526.0, 926'
ValueError: could not convert string to float: '525.0, 925'
ValueError: could not convert string to float: '524.0, 924'
ValueError: could not convert string to float: '523.0, 923'
ValueError: could not convert string to float: '522.0, 922'
ValueError: could not convert string to float: '521.0, 921'
ValueError: could not convert string to float: '520.0, 920'
ValueError: could not convert string to float: '519.0, 919'
ValueError: could not convert string to float: '518.0, 918'
ValueError: could not convert string to float: '517.0, 917'
ValueError: could not convert string to float: '516.0, 916'
ValueError: could not convert string to float: '515.0, 915'
ValueError: could not convert string to float: '514.0, 914'

@0xj7r
Copy link

0xj7r commented Jun 13, 2024

+1 here - now running into this error

[ERROR] ValueError: could not convert string to float: '599.0, 999'
Traceback (most recent call last):
...

@0xj7r
Copy link

0xj7r commented Jun 13, 2024

@oussama-gourari @the1daBread any thoughts on the origins of this error? Do you suspect it is an issue with prawcore iteself or the Reddit API?

@oussama-gourari
Copy link

@LilSpazJoekp
Copy link
Member

LilSpazJoekp commented Jun 13, 2024

This is an error with Reddit's API. It should be returning floats for headers.

@snarfed
Copy link

snarfed commented Jun 13, 2024

This is an error with Reddit's API. It should be returning floats for headers.

True! ...but also ideally prawcore should probably handle it better than crashing. 😆 #173 (comment)

@LilSpazJoekp
Copy link
Member

True, but this is rate limit code and handling it would likely involve discarding it and could cause your app to exceed the rate limits. This isn't a good thing for an API wrapper than handles rate limits for you.

@snarfed
Copy link

snarfed commented Jun 13, 2024

True! That seems like a policy choice though, right? You could easily fail closed, ie interpret it as over the rate limit, instead of failing open and interpreting as under the rate limit. Or something else entirely.

I'm sure you all will know the options and policy reasoning better than me! It just seems like surfacing an unexpected ValueError here, which most developers are unlikely to catch and will therefore crash them too, seems like a bad status quo.

@bboe
Copy link
Member

bboe commented Jan 25, 2025

I'm going to close this issue as it seems like a one off bug on Reddit's end that was resolved. For the PRAW project, it is customary for unexpected data to result in unexpected exceptions occurring.

@bboe bboe closed this as completed Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants