I had this class that performed perfectly in Linux.
class UrlRequestor(object):
def __init__(self, url, headers, data):
self.url = url
self.headers = headers
self.request = urllib2.Request(url)
self.data = data
self.data = data
if self.data:
self.request.add_data(self.data)
for headerName, headerContent in self.headers.iteritems():
self.request.add_header(headerName, headerContent)
def open(self):
self.content = urllib2.urlopen(self.request)
def getHeader(self, headerName):
return self.content.info().getheader(headerName)
def getReturnData(self):
return dict(json.loads(self.content.read()))
def getRawReturn(self):
return self.content.read()}
Which I have been trying to run on windows – with many errors including indentation I finally became stuck at this point.
I am apparently missing a ‘positional argument’ for the add_data method. Although I believe this is a symptom of a larger problem.
Here is the code as I have it.
class UrlRequestor(object):
def __init__(self, url, headers, data):
self.url = url
self.headers = headers
self.request = urllib2.Request(url)
self.data = data
self.data = data
if self.data:
self.request.add_data(self.data)
for headerName, headerContent in self.headers.iteritems():
self.request.add_header(headerName, headerContent)
def open(self):
self.content = urllib2.urlopen(self.request)
def getHeader(self, headerName):
return self.content.info().getheader(headerName)
def getReturnData(self):
return dict(json.loads(self.content.read()))
def getRawReturn(self):
return self.content.read()
I don’t mind reading, I don’t mind point in the right direction. At this point I am pretty stumped, and a little pointing wouldn’t hurt.
Many thanks guys.
EDIT********************************
For future information check the python version, installed 2.7.3 and ran exactly same code as on linux without a problem.
If you’re working with Python 2.7.x, then place
import urllib2at the beginning of your file.If you’re working with Python 3.x, then observe the note regarding the change to the
urllibfamily of libraries in Python 3.x:For your case, the library you want to use can be found in
urllib.request.Alternatively, on your Windows machine, elect to use the same version of Python that you have on your Linux box. There may be some other caveats in using Python 3.x on two platforms with the same code base that you’re not entirely accounting for.