I wonder why when I call requests.get() method consequentially, like this:
response = requests.get(url.format("set"))
print(response.status_code)
response = requests.get(url.format("map"))
print(response.status_code)
response = requests.get(url.format("list"))
print(response.status_code)
response = requests.get(url.format("vector"))
print(response.status_code)
response = requests.get(url.format("string"))
print(response.status_code)
I got OK status for all requests, but when I do it in the for loop, like:
for word in fIn :
response = requests.get(url.format(word))
if(response.status_code == 200):
print "OK"
else:
print(response.status_code)
print "Error"
print word
I got 400(Error) for all requests except the last one.
Additional info:
there is related question on SO, where are mentioned 2 ways of coping with this situation: wait, headers.
wait doesn't work in my situation
and about headers - I don't know what to provide there.
Update: specific version, that I am trying to implement:
from lxml import html
import requests
fOut = open("descriptions.txt","w")
with open('dummyWords.txt') as fIn:
for word in fIn :
print word
response = requests.get(url.format(word))
if(response.status_code == 200):
print "OK"
else:
print(response.status_code)
print(word)