How can I speed this up? (urllib2, requests)
<p>Problem: I am trying to validate a captcha can be anything from 0000-9999, using the normal requests module it takes around 45 minutes to go through all of them (0000-9999). How can I multithread this or speed it up? Would be really helpful if I can get the HTTP Status Code from the site to see if i successfully got the code correct or if it is incorrect (200 = correct, 400 = incorrect) If I could get two examples (GET and POST) of this that would be fantastic!</p>

<p>I have been searching for quite some time, most of the modules I look at are outdated (I have been using grequests recently)</p>

<pre><code>example url = https://www.google.com/
example params = captcha=0001
example post data = {"captcha":0001}
</code></pre>

<p>Thank you!</p>

<p><strong>You really shouldn't be trying to bypass a captcha programmatically!</strong></p>

<p>You could use several threads to make simultaneous requests but at that point the service you're attacking will most likely ban your IP. At the very least, they've probably got throttling on the service; There's a reason it's supposed to take 45 minutes.</p>

<p><a href="https://docs.python.org/2/library/threading.html" rel="nofollow">Threading in Python</a> is usually achieved by creating a thread object with a <code>run()</code> method containing your long running code. In your case, you might want to create a thread object which takes a number range to poll. Once instantiated, you'd call the <code>.start()</code> method to have that thread begin working. If any thread should get a success message it would return a message to the main thread, halt itself, and the main thread could then tell all the other threads in the thread pool to stop.</p>

python python-requests urllib2