Commits

Erik Svensson  committed 25e9b8e

Fixed HTTPHandler encoding issues in Python 3.
Fixed HTTP header handling in Python 3.

  • Participants
  • Parent commits 1588000

Comments (0)

Files changed (2)

File transmissionrpc/client.py

                     LOGGER.info('Server responded with 409, trying to set session-id.')
                     if request_count > 1:
                         raise TransmissionError('Session ID negotiation failed.', error)
-                    if 'x-transmission-session-id' in error.headers:
-                        self.session_id = error.headers['x-transmission-session-id']
-                        headers = {'x-transmission-session-id': str(self.session_id)}
-                    else:
+                    sessionId = None
+                    for key in list(error.headers.keys()):
+                        if key.lower() == 'x-transmission-session-id':
+                            sessionId = error.headers[key]
+                            self.session_id = sessionId
+                            headers = {'x-transmission-session-id': str(self.session_id)}
+                    if sessionId is None:
                         debug_httperror(error)
                         raise TransmissionError('Unknown conflict.', error)
                 else:

File transmissionrpc/httphandler.py

         install_opener(opener)
 
     def request(self, url, query, headers, timeout):
-        request = Request(url, query, headers)
+        request = Request(url, query.encode('utf-8'), headers)
         try:
             if (sys.version_info[0] == 2 and sys.version_info[1] > 5) or sys.version_info[0] > 2:
                 response = urlopen(request, timeout=timeout)
                 raise HTTPHandlerError(httpmsg='urllib2.URLError: %s' % (error.reason))
         except BadStatusLine as error:
             raise HTTPHandlerError(httpmsg='httplib.BadStatusLine: %s' % (error.line))
-        return response.read()
+        return response.read().decode('utf-8')