I am writing a Python 2.7 script that takes a URL and checks if the server is responding if the server is online then it takes a file and combines it with the server address and then checks if the file is on the server depending on the results then it attempts to download the file the code is below.
If someone could explain to me what is wrong with my code and how to fix it along with how the error occurred i would appreciate it.
The downloading code comes from pythonforbeginners.com I have tried asking this on StackOverflow and just got answers basically telling me to figure it out for myself and I got blocked from asking questions hopefully someone here can help me.
#!/usr/bin/python
import urllib2
Server = urllib2.urlopen('https://www.google.com')
File = '/Download.txt'
URL = Server + File
if URL.getcode() == 200:
Response = urllib2.urlopen(Server)
Write = open(file, "w")
Write.write(response.read())
Write.close()
else:
print (' Just Testing')
Looks like you are confusing your variables. "Server" is not the URL string. It's an instance of urllib2 that is there for handy usage.