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

rate limits? #2

Open
iamvishnurajan opened this issue Feb 18, 2024 · 7 comments
Open

rate limits? #2

iamvishnurajan opened this issue Feb 18, 2024 · 7 comments
Labels
feature a feature request or enhancement handled-i-think Issues/features that I think are handled
Milestone

Comments

@iamvishnurajan
Copy link

Hi,

Thank you for building this as I like being able to work in R. I was wondering if there is a way to get the current rate limits? I seem to be running into some kind of limit when trying to delete records on bsky via bskyr but I am unable to figure out which one.

Thanks much

@christopherkenny
Copy link
Owner

Thanks for using the package @iamvishnurajan. Could you provide any context for how you're doing this? For example, are you looping through calls to bs_delete_record() and letting it re-authenticate each time? What error do you receive?

@CrumpLab
Copy link

I have hit a similar issue. My case is adding people to a list.

I have a loop like this, which adds a single user to a list.

for(i in 1:x){
      bs_create_record(
        collection =  'app.bsky.graph.listitem',
        record = list(
          '$type' = 'app.bsky.graph.listitem',
          'subject' = follows$did[i],
          'list' = '{my list here}',
          'createdAt' = bs_created_at()
           )
        )
      Sys.sleep(1)
}

I had run set_bluesky_user() and set_bluesky_pass() once at the beginning of the session. I tried various settings for Sys.sleep() to slow the requests. Yesterday I got through about 100+ iterations before the following error:

Error in `httr2::req_perform()`:
! HTTP 429 Too Many Requests.
Backtrace:
  1. bskyr::bs_get_follows("mattcrumplab.bsky.social", limit = 500)
  9. bskyr::bs_auth(user, pass)
 13. httr2::req_perform(req)

Based on this rate limit information on this page I was surprised that I was hitting limits, but I'm very new this api and haven't read all the docs: https://docs.bsky.app/blog/rate-limits-pds-v3.

Interestingly after not touching it since yesterday evening, I am still getting this 429 error this morning.

Thanks again for the package and for any insights on the rate limit issue.

@CrumpLab
Copy link

CrumpLab commented Feb 27, 2024

I was able to work out my issue thanks to your comment about "re-authenticating every time".

In my loop I guess bs_create_record() was calling bs_auth() and re-authenticating every time. This caused me to hit the createSession limit, and be blocked out for 24 hours.

In case it is is useful for others, this ended up working like a charm.

#run once to start session
my_auth <- bs_auth(user,pass) # save authentication in a variable

for(i in 1:x){
      bs_create_record(
        collection =  'app.bsky.graph.listitem',
        record = list(
          '$type' = 'app.bsky.graph.listitem',
          'subject' = follows$did[i],
          'list' = '{my list here}',
          'createdAt' = bs_created_at(),
           user = "myusername",
           pass = "mypasscode",
           auth = my_auth #use the existing auth var, don't call bs_auth()
           )
        )
      Sys.sleep(1)
}

Apologies for jumping in on this issue. I also think it would be great to have a verbose option for looking at rate limit returns.

Thanks again for your work on this package!

@iamvishnurajan
Copy link
Author

Hi, thanks for the tip and no problem at all to jump in here. I also was doing a similar for loop with a sys.sleep(), but when I get some time to work on my code more next week, I'll try a similar authentication method.

In my case, I was able to rerun after 5-10 minutes, so perhaps mine may be a different issue. I found I could delete about 30 records before it rate limited me.

christopherkenny added a commit that referenced this issue Feb 28, 2024
@iamvishnurajan
Copy link
Author

Hi, just to close this, adding a similar auth statement in my code worked for me also. I was able to delete more than 30 records without a problem now using the following.

for (pd in 1:nrow(posts_delete)){
  bs_delete_record(collection="app.bsky.feed.post",
                   rkey=posts_delete$record[pd],
                   auth=my_auth)
  Sys.sleep(0.5)
}

@christopherkenny christopherkenny added the feature a feature request or enhancement label Nov 20, 2024
@christopherkenny christopherkenny added this to the 0.2.0 milestone Nov 21, 2024
@christopherkenny christopherkenny added the handled-i-think Issues/features that I think are handled label Dec 1, 2024
@MatthBogaert
Copy link

The above solution worked for me. However, I had closed my R session and had to run the line:
auth <- bs_auth(user = bs_get_user(), pass = bs_get_pass())again. The result was that I bumped into the request limits.

So to be clear, the best solution to avoid this would be to also save your auth object and load this again and always add this with each request like mentioned above?

@iamvishnurajan
Copy link
Author

As an aside, I think there was something specific about bsky yesterday afternoon/evening (Jan 21 Eastern time) and this morning (Jan 22) about rate limits. Scripts I have that normally run fine, errored out due to rate limit issues.

Mine seem to be running fine as of a short time ago, so I would try again and see if your issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement handled-i-think Issues/features that I think are handled
Projects
None yet
Development

No branches or pull requests

4 participants