Why do the same requests result in different status codes 200 vs. 429 on two machines?

Viewed 226

Here is my script:

import requests, os

ips = ['158.46.169.208','158.46.169.252','158.46.169.76','158.46.171.23','158.46.172.217','158.46.172.55','158.46.172.98','158.46.173.104']
headers =  {"User-Agent": "Edg/90.0.818.56"}

os.system("python3 --version") #On Windows it changes to os.system("python --version")

for i in ips:
    pr = {'http':"http://"+"abcd-"+i+':xyz@example.io:22225','https':'https://'+"abcd-"+i+':xyz@example.io:22225'}
    res1 = requests.get("https://www.google.com/search?q=butter",headers=headers, proxies= pr)
    print(requests.get("https://www.httpbin.org/ip",proxies = pr,headers=headers).text)
    print(res1.status_code)

Output on Windows 10:

Python 3.8.2
{
  "origin": "158.46.169.208"
}

200
{
  "origin": "158.46.169.252"
}

429
{
  "origin": "158.46.169.76"
}

200
{
  "origin": "158.46.171.23"
}

200
{
  "origin": "158.46.172.217"
}

200
{
  "origin": "158.46.172.55"
}

200
{
  "origin": "158.46.172.98"
}

Output on Ubuntu 18.04:

Python 3.8.0
{
  "origin": "158.46.169.208"
}

429
{
  "origin": "158.46.169.252"
}

429
{
  "origin": "158.46.169.76"
}

429
{
  "origin": "158.46.171.23"
}

429
{
  "origin": "158.46.172.217"
}

429
{
  "origin": "158.46.172.55"
}

429
{
  "origin": "158.46.172.98"
}

429
{
  "origin": "158.46.173.104"
}

429

No matter how many times I run the script (even at the same time on two machines), the outputs remain always the same.

I am unable to understand why it blocks the requests on the Ubuntu. And at the same time, it allows the same requests from windows machine while using the same proxy.

I know 429 error means too many requests but then why it gets successful all the time I run on the Windows machine?

EDIT: I have a dual boot laptop, so I logged in to Ubuntu 18.04 on my laptop on which I have windows too. And it seems to work fine here. Same behavior as of Windows. But still it fails when I run it on my server having Ubuntu 18.04 and again everything is same as above.

1 Answers

You need to understand the meaning of HTTP response 200 (HTTP OK) and 429 (Too many requests), as explained in this Wikipedia article.

As you can see, the problem seems not to be due to your program, but to the machine you're working with, who seems to be launching too many requests (at least that's how the server understands it).

In short, you are dealing with a network related issue, you might consider talking about this issue with your network administrator.

Related