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.