It's probably one of those things that comes with a server through an application.
1.GUI
It's tkinter.
1 #-*-coding:utf-8-*-2 fromTkinterImport*3 ImportTkinter.filedialog4 ImportRequests5 6 7 defUpload ():8 Print('Upload')9Selectfilename = Tkinter.filedialog.askopenfilename (title='Select File')#Select FileTen OneR = Requests.post ('Http://127.0.0.1:8000/upload', files={'file': Open (Selectfilename,'RB')}) A Print(R.content.decode ('Utf-8')) -SetText = R.content.decode ('Utf-8') - Print(SetText.__class__) the E1.delete (0,end) - E1.insert (0,settext) - - defDownload (): +link =E1.get () -Files =requests.get (link) + files.raise_for_status () APath =Tkinter.filedialog.asksaveasfilename () at Print(files.content) -With open (path,'WB') as F: - f.write (files.content) - - -Root =Tk () inRoot.title ('Download') -Root.geometry ('+500+300') to +e1 = Entry (root,width=50) -E1.grid (row=0, column=0) the *BTN1 = Button (root,text='Upload', command=upload). Grid (Row=1, column=0,pady=5) $BTN2 = Button (root,text='Download', command=download). Grid (row=2, column=0,pady=5)Panax NotoginsengBtn3 = Button (root,text='Copy',). Grid (Row=3, column=0,pady=5) - theMainloop ()
The server to the Chinese file name is very unfriendly, as long as the Chinese file name appears, will error, make I am not in the mood, so the copy function is not implemented
And a bunch of messy codes, anyway, I don't understand.
A will have to use bytes () to the binary code, a will also decode and encode, a little fan ...
2. Server
With a huge simple frame, simply return to one or two pages on it, after all, the simulation
1 #-*-coding:utf-8-*-2 ImportWeb3URLs = (4 '/','Index',5 '/upload','Upload',6)#Routing7 8Render = Web.template.render ('Template')9 Ten classIndex: One defGET (self):#How to request a function name A returnRender.index () - - classUpload: the defPOST (self): -info = web.input (file = {})#Receive Data -filename = info['file'].filename -Thisfile = info['file'].file.read () +With open ('static/%s'%filename,'WB') as F: - f.write (thisfile) +s = Format ('http://127.0.0.1:8000/static/%s'%filename) A returns at - -App =web.application (URLs, Globals ()) - - if __name__=='__main__':#Entry function Judgment - App.run () in - #' server.py 127.0.0.1:8000 '
Before using Django to write a simple music site, a lot of details are forgotten, this use when feeling a bit like, also is a small memory of a bit
Summarize
Holiday is really boring, want to learn a bit more practical knowledge, but found that the impossible, really confused
This time, let's do a little thing, practice practiced hand.
Chinese is really unfriendly!!!!!!!!!!!!!!!!!!!!!!!!!!
Too TM trouble, but for these messy coding problems, I can shorten the time spent 80%!!!
What a terrible number, but this is the problem of no brain, can toss the people die
Oh, yes. The Post method in the Requsets package, when the parameter has files=, the file name of this upload cannot be Chinese
Otherwise, the server won't receive the parameters.
Finally changed the urllib3.py source under the decoding of a function, from the ' ascll ' changed to ' Utf-8 ', in order to upload Chinese file name files
However, when downloading the Chinese file, there will be errors such as access
http://127.0.0.1:8000/static/hello. txt, the server side will error "Wsgi what", this error, baidu,google have no, no solution, give up, the mood is very poor
Python server file upload download +gui "Tkinter"