Python - Files wont download
Question: Here's My code, all the urls are in a Config Parser format file. When the
button is pressed files will not download. What did go wrong? I used urllib
should I have used urllib2? Some of the functions may be there but not used
just ignore that.

    
    
    import wx
    import ConfigParser
    import urllib
    
    def Download(url):
        response = urllib.urlopen(url).read()
        doned = wx.MessageDialog("Download Done")
        doned.ShowModal()
        doned.Destroy()
    
    #First thing i gona do is Parse 98 box data
    BoxParser = ConfigParser.RawConfigParser() #Set Raw
    BoxParser.read("98.box") #Mount into 98.box
    #Get Vars, and print them
    
    WxTitle = BoxParser.get("meta_data","Window_title") #get the window title
    Application = BoxParser.get("meta_data","Application") #Get app name
    Desc = BoxParser.get("meta_data","Description") #Get the description of the app
    Author = BoxParser.get("meta_data","Author") #Of course! I dont wanna be plagurized
    Contact = BoxParser.get("meta_data","Contact_Info") #My Contact Info
    Date = BoxParser.get("meta_data","Date") #Date when the current update was made
    #UpdateUrl = BoxParser.get("meta_data","Update_url") #Url to update
    #BoxUp = BoxParser.get("meta_data","Update_box") #Url to update 98.box
    # Meta Data loaded
    
    #time to load the firmwares
    e660 = BoxParser.get("Firmware_links","660") #6.60
    e6602 = False
    e660g = BoxParser.get("Firmware_links","660go") #6.60 Go Eboot
    e6602g = False
    e639 = BoxParser.get("Firmware_links","639") #6.39
    e6392 = False
    e639g = BoxParser.get("Firmware_links","639go") #6.39 Go Eboot
    e6392g = False
    e635 = BoxParser.get("Firmware_links","635") #6.35
    e6352 = False
    e635g = BoxParser.get("Firmware_links","635go") #6.35 Go Eboot
    e6352g = False
    e620 = BoxParser.get("Firmware_links","620") #6.20
    e550 = BoxParser.get("Firmware_links","550") #5.50
    e5502 = False
    e500 = BoxParser.get("Firmware_links","500") #5.00
    e5002 = False
    e401 = BoxParser.get("Firmware_links","401") #4.01
    e4012 = False
    #Firmwares Loaded
    
    
    
    
    
    
    
    
    def BoxUpdate():
        Download(Update_box)
        #Check if DD equ true so we can post the MSG
        if downloaddone == True:
            Done2 = wx.MessageDialog(self,"Download Done, 98.Box Updated!")
            Done2.ShowModal()
            Done.Destroy()
    
    
    #Time to get out Gui
    class FrameClass(wx.Frame): #Finally making the gui!
        def __init__(self,parent,title): #making init!
            app = wx.Frame
            app.__init__(self,parent,title=WxTitle,size = (340,280)) #set window size
    
            Menu = wx.Menu() #Lets make a menu!
            panel = wx.Panel(self) #set the panel var
    
            contact = Menu.Append(wx.ID_NONE,"&Contact Info") #add update thing
            self.Bind(wx.EVT_MENU,self.contact1,contact) #Add event for Update
            fwMsg = wx.StaticText(panel, label='Firmware', pos=(59,25))
            fwlist = wx.ComboBox(panel,pos=(118,22), choices=["6.60","6.60 Go/N1000","6.39","6.39 Go/N1000","6.35 Go/N1000","5.50","5.00","4.01"])
            self.Bind(wx.EVT_COMBOBOX, self.getsel, fwlist)
            downloadbutton = wx.Button(panel, label="Download FW", pos=(100,76))
            self.Bind(wx.EVT_BUTTON, self.DLB, downloadbutton)
    
            #now for the member!
            TopM = wx.MenuBar()
            TopM.Append(Menu, "Tool Opt")
            self.SetMenuBar(TopM)
            self.Show(True)
    
        def DLUpdate(self,e):
            #Check if DD equ true so we can post the MSG
            Download(Update_url)
            print "downloading"
    
            Done = wx.MessageDialog(self,"Download Done, download stored in \"DLBOXV$.zip\" file")
            Done.ShowModal()
            Done.Destroy()
    
        def contact1(self,e):
            con = wx.MessageDialog(self,Contact)
            con.ShowModal()
            con.Destroy()
    
    
        def getsel(self,e):
            i = e.GetString()
            if i == "6.60":
                e6602 = True
                print e6602,"660"
            else:
                e6602 = False
                print e6602,"660"
    
            if i == "6.60 Go/N1000":
                e6602g = True
                print e6602g,"660 go"
            else:
                e6602g = False
                print e6602g,"660 go"
    
            if i == "6.39":
                e6392 = True
                print e6392,"639"
            else:
                e6392 = False
                print e6392,"639"
    
            if i == "6.39 Go/N1000":
                e6392g = True
                print e6392g,"639 go"
            else:
                e6392g = False
                print e6392g,"639 go"
    
            if i == "6.35 Go/N1000":
                e6352g = False
                print e6352g,"635 go"
            else:
                e6352g = False
                print e6352g,"635 go"
    
            if i == "5.50":
                e5502 = True
                print e5502,"550"
            else:
                e5502 = False
                print e5502,"550"
    
            if i == "500":
                e5002 = True
                print e5002,"500"
            else:
                e5002 = False
                print e5002,"500"
    
            if i == "401":
                e4012 = True
                print e4012,"401"
            else:
                e4012 = False
                print e4012,"401"
    
    
    
        def DLB(self,e):
            if e6602 == True:
                Download(e660)
            elif e6602g == True:
                Download(e660g)
            elif e6392 == True:
                Download(e639)
            elif e639g == True:
                Download(e639g)
            elif e6352g == True:
                Download(e635g)
            elif e5502 == True:
                Download(e550)
            elif e5002 == True:
                Download(e500)
            elif e4012 == True:
                Download(e401)
    
    G = wx.App(False)
    Win = FrameClass(None,WxTitle)
    G.MainLoop()
    

But at the function `Download(url)` will not function, it will not download

    
    
    def Download(url):
            response = urllib.urlopen(url).read()
            doned = wx.MessageDialog("Download Done")
            doned.ShowModal()
            doned.Destroy()
    

what triggers `Download(url)` is a few if and elsif statements

    
    
    def getsel(self,e):
                i = e.GetString()
                if i == "6.60":
                    e6602 = True
                    print e6602,"660"
                else:
                    e6602 = False
                    print e6602,"660"
    
                if i == "6.60 Go/N1000":
                    e6602g = True
                    print e6602g,"660 go"
                else:
                    e6602g = False
                    print e6602g,"660 go"
    
                if i == "6.39":
                    e6392 = True
                    print e6392,"639"
                else:
                    e6392 = False
                    print e6392,"639"
    
                if i == "6.39 Go/N1000":
                    e6392g = True
                    print e6392g,"639 go"
                else:
                    e6392g = False
                    print e6392g,"639 go"
    
                if i == "6.35 Go/N1000":
                    e6352g = False
                    print e6352g,"635 go"
                else:
                    e6352g = False
                    print e6352g,"635 go"
    
                if i == "5.50":
                    e5502 = True
                    print e5502,"550"
                else:
                    e5502 = False
                    print e5502,"550"
    
                if i == "500":
                    e5002 = True
                    print e5002,"500"
                else:
                    e5002 = False
                    print e5002,"500"
    
                if i == "401":
                    e4012 = True
                    print e4012,"401"
                else:
                    e4012 = False
                    print e4012,"401"
    
    
    
            def DLB(self,e):
                if e6602 == True:
                    Download(e660)
                elif e6602g == True:
                    Download(e660g)
                elif e6392 == True:
                    Download(e639)
                elif e639g == True:
                    Download(e639g)
                elif e6352g == True:
                    Download(e635g)
                elif e5502 == True:
                    Download(e550)
                elif e5002 == True:
                    Download(e500)
                elif e4012 == True:
                    Download(e401)
    


Answer: > What did go wrong? I used urllib should I have used urllib2?

Yes. The fact that just adding the `2` to your code fixes the problem is
obviously proof of that, but it doesn't explain much.

As the docs for
[`urllib.urlopen`](https://docs.python.org/2/library/urllib.html#urllib.urlopen)
say:

> Deprecated since version 2.6: The `urlopen()` function has been removed in
> Python 3 in favor of `urllib2.urlopen()`.

This doesn't mean that they stopped fixing bugs in `urllib` as of 2.6 (there
was a bug fix as late as 2.7.9), but it does mean that missing functionality
will never be added. That includes, among other things, some kinds of HTTP
authentication, redirections, HTTPS with non-standard CAs, proxy settings, and
proxy authentication.

Without knowing anything at all about the problem besides "the download
doesn't happen", or what URL you're trying to download (you seem to be passing
in a variable named `Update_box` that isn't assigned anywhere), or the setup
you're running on, it's impossible to know exactly which one of these problems
(or any others) is the key.

