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

response status 429 Too Many Requests: Rate limit exceeded #25

Open
Volvalzark opened this issue Oct 30, 2023 · 12 comments
Open

response status 429 Too Many Requests: Rate limit exceeded #25

Volvalzark opened this issue Oct 30, 2023 · 12 comments

Comments

@Volvalzark
Copy link

この問題を解決するために、APIリクエストに秒単位の遅延を設定することは可能ですか?

@mmpx12
Copy link
Owner

mmpx12 commented Oct 30, 2023

@Volvalzark english plz

@Volvalzark
Copy link
Author

Sorry, I thought I sent it in English, but I sent it in Japanese. Is it possible to set a delay in seconds for API requests to solve this problem?

@Kameshennyn
Copy link

Same issue there, only happens once logged

@mmpx12
Copy link
Owner

mmpx12 commented Nov 1, 2023

Since i'm using go routine, i first need to set the number of go routines it used before setting up a delay (without adding delay will change nothing).

@Volvalzark
Copy link
Author

I don't know the appropriate number of go routines, so I can't really say, how many is appropriate?

@gzygood
Copy link

gzygood commented Nov 13, 2023

“response status 429 Too Many Requests: Rate limit exceeded”
Yes, it's easy to see this!

@shunnag
Copy link

shunnag commented Dec 16, 2023

I am modifying it as follows.

	wg := sync.WaitGroup{}
	for tweet := range scraper.GetTweets(context.Background(), usr, nbrs) {
		time.Sleep(2 * time.Second) // Sleep after each tweet is fetched 
		if tweet.Error != nil {
			wg.Wait() //Wait to prevent program from exiting during image acquisition
			fmt.Println(tweet.Error)
			os.Exit(1)
		}
		if vidz {
			time.Sleep(5 * time.Second) // Extra long sleep when acquiring video 
			wg.Add(1)
			go videoUser(&wg, tweet, output, retweet)
		}
		if imgs {
			time.Sleep(1 * time.Second) //A little extra sleep during image acquisition
			wg.Add(1)
			go photoUser(&wg, tweet, output, retweet)
		}
	}
	wg.Wait()

@mmpx12
Copy link
Owner

mmpx12 commented Dec 16, 2023

@shunnag you can also use: scraper.WithDelay(2) instead of time.Sleep(2 * time.Second) // Sleep after each tweet is fetched .

but for:

		if tweet.Error != nil {
+     		wg.Wait() //Wait to prevent program from exiting during image acquisition
			fmt.Println(tweet.Error)
			os.Exit(1)
		}
		if vidz {
+     		time.Sleep(5 * time.Second) // Extra long sleep when acquiring video 
			wg.Add(1)
			go videoUser(&wg, tweet, output, retweet)
		}
		if imgs {
+      		time.Sleep(1 * time.Second) //A little extra sleep during image acquisition
			wg.Add(1)
			go photoUser(&wg, tweet, output, retweet)
		}
	}

did you tried ans Is it working?

@shunnag
Copy link

shunnag commented Dec 16, 2023

@mmpx12
It appears to be functioning correctly. There is a 2-second delay applied to all API accesses, and an additional delay is added when fetching tweets with the "imgs, vids" option enabled, even if the tweet itself doesn't contain any images or videos. We could potentially adjust the numbers to align with the 429 rate limit in order to increase the acquisition speed, but for now, it's running smoothly without causing errors, albeit at a slower pace.

@mmpx12
Copy link
Owner

mmpx12 commented Dec 16, 2023

@shunnag This should be added with a flag like '-S|--slow'. I use a different proxy every time I run twmd (not for a single tweet, but for -a, -v, or -i) so I don't encounter 429 error.
Another option should be to add '-f|--fast' to enable goroutine. But I'm not sure if without goroutine and without sleep, 429 error would occur.

@shunnag
Copy link

shunnag commented Dec 17, 2023

@mmpx12
like this?

-	var nbr, single, output string
+	var nbr, single, output, delay string
	var retweet, all, printversion, nologo, login, twofa bool
	op.On("-B", "--no-banner", "Don't print banner", &nologo)
+	op.On("-d", "--delay SECOND(S)", "Use specified seconds delay for API access", &delay)
	op.Exemple("twmd -u Spraytrains -o ~/Downlaods -a -r -n 300")
	wg := sync.WaitGroup{}

+	if delay == "" {
+		delay = "0"
+	}
+	delay64, _ := strconv.ParseInt(delay, 10, 64)
+
	for tweet := range scraper.GetTweets(context.Background(), usr, nbrs) {

and use
time.Sleep(time.Second * time.Duration(delay64)) in loop
or
scraper.WithDelay(delay64)

@tazeps
Copy link

tazeps commented Mar 21, 2024

I am also encountering this issue and was thinking of having a delay function. which version is working best for you guys ?
I'd wait for a new release if @mmpx12 will incorporate it otherwise I may try to add it. though i'm new to using github for software so i might struggle

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

6 participants