+ 1
Getting Problem On Code with requests module
hello, i have been working on a python program where i have to check the http status codes of list urls with the help of requests module A txt file each line contains an url i have written a small program to check http status of urls but failing to handle it here is the code to my program https://code.sololearn.com/cwhXSEga65nN/?ref=app
3 Answers
+ 5
There are multiple issues that can cause problems:
- there must be a txt file in the same folder as the program code is stored (this is not the case in playground)
- file content has to be like http://www.amazon.com line by line
- module requests has to be installed (this is not the case in playground)
- after reading a line from the file, the trailing new line characters has to be removed. this could be done like:
r = requests.get(line.strip())
If all these items work, the code runs properly:
http://www.amazon.com
503
End
http://www.apple.com
200
End
+ 1
not its not runnning like that, i run the program on pycharm
the file.txt file conatins urls like
http://google.com
http://python.org
http://facebook.com
let me try with line.strip() function
+ 1
(Problem Solved)
there was a problem with reading lines
i forget to use strip()