Skip to content

Commit

Permalink
request body should be represented by bytes
Browse files Browse the repository at this point in the history
fix #35
  • Loading branch information
indeyets committed Aug 18, 2014
1 parent b546cc6 commit 0531859
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions SPARQLWrapper/Wrapper.py
Expand Up @@ -465,7 +465,7 @@ def _createRequest(self):
else: # URL-encoded
request = urllib2.Request(uri)
request.add_header("Content-Type", "application/x-www-form-urlencoded")
request.data = self._getRequestEncodedParameters(("update", self.queryString))
request.data = self._getRequestEncodedParameters(("update", self.queryString)).encode('ascii')

This comment has been minimized.

Copy link
@wikier

wikier Aug 19, 2014

Member

then I'd move the encoding in the method

This comment has been minimized.

Copy link
@indeyets

indeyets Aug 19, 2014

Author Contributor

that doesn't work. method is used in other places too. explicit encoding is required for .data, but for the query (see case above) it works implicitly

This comment has been minimized.

Copy link
@wikier

wikier Aug 25, 2014

Member

right

else:
#protocol details at http://www.w3.org/TR/sparql11-protocol/#query-operation
uri = self.endpoint
Expand All @@ -478,7 +478,7 @@ def _createRequest(self):
else: # URL-encoded
request = urllib2.Request(uri)
request.add_header("Content-Type", "application/x-www-form-urlencoded")
request.data = self._getRequestEncodedParameters(("query", self.queryString))
request.data = self._getRequestEncodedParameters(("query", self.queryString)).encode('ascii')
else: # GET
request = urllib2.Request(uri + "?" + self._getRequestEncodedParameters(("query", self.queryString)))

Expand Down
6 changes: 5 additions & 1 deletion test/wrapper_test.py
Expand Up @@ -76,7 +76,11 @@ def _get_parameters_from_request(request):
if request.get_method() == 'GET':
pieces_str = urlparse(request.get_full_url()).query
else:
pieces_str = request.data
if sys.version < '3':
pieces_str = request.data
else:
pieces_str = request.data.decode('ascii')

return parse_qs(pieces_str)

@staticmethod
Expand Down

0 comments on commit 0531859

Please sign in to comment.