Skip to content

RecordingConnection string handling issues #1253

@adambaratz

Description

@adambaratz

I was working on test coverage for topic search (see #1252). When recording an example API response, the test runner got thrown off by a non-breaking space in the content:

Traceback (most recent call last):
  File "tests/Topic.py", line 67, in testSearch
    self.assertListKeyEqual(self.g.search_topics("python"), attrgetter("name"), expected_names)
  File "tests/Framework.py", line 312, in assertListKeyEqual
    realKeys = [key(element) for element in elements]
  File "github/PaginatedList.py", line 61, in __iter__
    newElements = self._grow()
  File "github/PaginatedList.py", line 73, in _grow
    newElements = self._fetchNextPage()
  File "github/PaginatedList.py", line 198, in _fetchNextPage
    headers=self.__headers
  File "github/Requester.py", line 268, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url)))
  File "github/Requester.py", line 328, in requestJson
    return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
  File "github/Requester.py", line 381, in __requestEncode
    status, responseHeaders, output = self.__requestRaw(cnx, verb, url, requestHeaders, encoded_input)
  File "github/Requester.py", line 405, in __requestRaw
    response = cnx.getresponse()
  File "tests/Framework.py", line 129, in getresponse
    self.__writeLine(output)
  File "tests/Framework.py", line 140, in __writeLine
    self.__file.write(line + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 2437: ordinal not in range(128)

I haven't looked too closely at the code, but this looks related to the fact that this class treats the response body as ASCII and UTF-8 in different places.

There's another issue with the same line in Python 3. Files opened in binary mode expect to receive bytes and '\n' is a string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions