Python 请求有效负载中的符号的库Unicode错误

Python 请求有效负载中的符号的库Unicode错误,python,Python,我正在尝试这样做一个api调用 def getSearchResults(self, sid): headers = {'accept': 'application/xml'} payload = {'output_mode': 'csv' , 'count' : 0 } baseurl = "%s://%s/%s/%s/results" % (self.protocol, self.host, 'services/search/jobs', s

我正在尝试这样做一个api调用

 def getSearchResults(self, sid):
        headers = {'accept': 'application/xml'}
        payload = {'output_mode': 'csv' , 'count' : 0 }
        baseurl = "%s://%s/%s/%s/results" % (self.protocol, self.host, 'services/search/jobs', sid)
        response = ""
        try:
            t = time.time()
            response = requests.get(baseurl,params=payload, auth=(self.userName, self.password), headers=headers,verify=False, timeout=self.request_timeout_sec)
            #print("Splunk Results API URL '%s' took %s secs.Response: '%s'" % ( baseurl, str(round(time.time()-t, 3)), str(response)))
            print(response.url)
        except Exception as ex:
            print(str(ex))
        return response.text
但是我得到了这个错误

UnicodeEncodeError:“ascii”编解码器无法对位置330854处的字符u'\u2013'进行编码:序号不在范围128中
当我在paload中给出第二个键值对时,就会出现这个问题。请尝试将unicode url作为请求传递。差不多

unicode_url = u'https://test.com/test/?param1=1234'

嗨,伙计们,我已经解决了这个问题

返回response.text.encodeutf-8


谢谢大家

该错误适用于U+2013 EN破折号,而不是符号。是否检查了printresponse.content?你在谷歌上查过什么字符有代码u'\u2013'吗?它在内容中的什么地方?可能内容使用的编码与utf-8不同,转换时会出现问题。printresponse.content提供了我想要的内容,但由于存在上述错误,我对python还不熟悉,因此我不知道您需要提取什么内容并提供一个新的内容。关于您的案例,例如,如果您明确指出错误发生的位置,包括回溯和硬编码您得到的结果,则会有所帮助,这样人们就不必进行相同的查询。此外,确保你做了一些关于你得到的错误和可能的原因的研究。这里有上百个类似错误的问题!另外,作为这里的新用户,请确保您使用了并读取了。no,该字符串没有属性。text