http - Python 3 - use urllib to run .jsp script and retrieve results -


i have csv file created everytime run .jsp file on tomcat server. when done manually click on link "servers.jsp" , file "server_list.csv" starts downloading.

i in python v3 script can iterate on results , automate process.

here code send post server, pass auth values in url , receive generated .csv

import urllib.request  link = "https://tomcat.server.org:8443/html/scripts/servers.jsp" userpass = {'pass': '12345', 'user': 'admin'}  data = urllib.parse.urlencode(userpass) data = data.encode('utf-8')  req = urllib.request.request(link, data) resp = urllib.request.urlopen(req) respdata = resp.read()  savefile = open(myfile.csv,'w') savefile.write(str(respdata)) savefile.close() 
  • a file indeed created not full file first row( or parts of) of file should contain. why doesn't whole file downloaded ?
  • how can print string value of urllib.request.urlopen(req) ?

note: can not use module not come default distro of python 3

have tried urllib.request.urlretrieve instead?

https://docs.python.org/3.0/library/urllib.request.html#urllib.request.urlretrieve

note: if url points local file, or valid cached copy of object exists, object not copied

on side note, take @ requests package nice wrapper built around urllib. find easier use.

http://docs.python-requests.org/en/latest/


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -