1
votes

have a post call as below:

http://localhost:8086/service/records/bulkimport?overwrite=true&classroom=grade1&dir=C:\Users\temp\classroomRecords\grade1

tried to implement in python3.6 using urllib as below:

from urllib.request import urlopen, URLError, Request
from urllib.parse import urlencode

loadRecordsRestCall = 'http://localhost:8086/service/records/bulkimport'
values = {'overwrite' : 'true',
      'classroom' :  'grade1',
      'dir' : 'C:\\Users\\temp\\classroomRecords\\grade1'}
data = urlencode(values)
data = data.encode('ascii')
req = Request(self.loadRecordsRestCall, data)
with urlopen(req) as loadRecordsRestCall:
    print("Status: %s" % loadRecordsResponse.getcode()) 
    print("Response: %s" % loadRecordsResponse.read()) 

But each time it showed error code 500, did a research online, do not want to user external library, if just using urllib, how to make it work.

Below are the error message, does anyone know what is wrong here: Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Python36\lib\urllib\request.py", line 223, in urlopen return opener.open(url, data, timeout) File "C:\Program Files\Python36\lib\urllib\request.py", line 532, in open response = meth(req, response) File "C:\Program Files\Python36\lib\urllib\request.py", line 642, in
http_response 'http', request, response, code, msg, hdrs) File "C:\Program Files\Python36\lib\urllib\request.py", line 570, in error return self._call_chain(*args) File "C:\Program Files\Python36\lib\urllib\request.py", line 504, in _ call_chain result = func(*args) File "C:\Program Files\Python36\lib\urllib\request.py", line 650, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 500: Request failed.

1
Have you looked at the error log yet?Ignacio Vazquez-Abrams
yes, I checked the error log, pasted in the original post too, but still can not figure out what is wrong here, could you suggest something to check hereuser9571515
That's just the traceback of the client code. Where is the error log of the server?Ignacio Vazquez-Abrams
Thanks, I am checking now, there are some nullpoint error, the part I don't understand is I tried the full url call with all the three parameters set in Fiddler, it works, but in the python code, not working, means its not service or api prolbrom, must be in the python urllib rest call, not make the rest call right.user9571515
the error in the service seems the folder path is not passed in right, do you have any idea for how should pass in the folder path hereuser9571515

1 Answers

0
votes

This is resolved, and turned out the service side API is requiring query param. so I used formated url string to make the call.