'Get throught url in python loop

I have to collect data from a url with a special tag i have a function that generate my url and i try in a for loop to call different url and add the dataframe into a list like so.

L=[]

for i in range(10):

   url=urls(TAG.Tag_I[i])

   response=requests.get(url, auth=(user, password))



   df = pd.read_json(response.text)  # resultat = datafram avec PointName, Value, Timestamp
     
   L+=[df]

However i get Max retries exceeded with url but when i do this loop directly into my terminal it works. I can't figure out what the issue is.



Solution 1:[1]

i found the solution by using a loop with a try and except.The issue was when the request got a timeout it returned an error without retrying.Here is what i came up with.

L=[]

for i in range(len(TAG)):

   url=urls(TAG.Tag_I[i])



   while len(L)==i:

       try:
           response=requests.get(url, auth=(user, password))
        
           df = pd.read_json(response.text)  # resultat = datafram avec PointName, Value, Timestamp
             
           L+=[df]
       except:
           None
        

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mambapowa