简体   繁体   English

被此错误tweepy所迷惑:无法发送请求:标头指示已编码的主体,但主体不可解码

[英]Confused by this error tweepy: Failed to send request: Headers indicate a formencoded body but body was not decodable

I have a list (in python) with Spanish characters , such as these : ó, í, ñ , I am using the Tweepy library and want to make a api.status_update (list [ element ] ) I get this error ... 我有一个带有西班牙语字符的列表(在python中),例如:ó,í,ñ,我正在使用Tweepy库,并想制作一个api.status_update (列表[element]),但出现此错误...

tweepy.error.TweepError : Failed to send request : \
    Indicate Headers formencoded body to body but was not decodable . *

List element example: 列表元素示例:

u'En esta ocasi\\xf3n 20 familias de las diferentes salas del centro cultural, 80 personas recibieron su certificaci\\xf3n u'en esta ocasi \\ xf3n 20口之家拉丁美洲文化中心,80角色su certificaci \\ xf3n

Snippet's code: 片段代码:

for ultag in sopa.find_all('ul', {'class': 'content'}):
    for litag in ultag.find_all('li'):
        url = litag.find('a')
        textUrl = litag.find('span', {'id': 'noticias_item_extract'})
        urlCorta = shortenerUrl(url.get('href'))
        i = random.randint(75, 81)
        listaCompleta.append(u''.join(textUrl.p.text[:i]+ '...' + ' ' + urlCorta+ ' ' + '#Hash'))

Other snippet: 其他摘要:

for i in listaCompleta:
    api.update_status(i.encode('utf-8'))
    time.sleep(random.randint(30, 45))

In short : You're not encoding your characters properly. 简而言之 :您没有正确编码字符。 You need to follow the encoding provided in the second link where they must be ASCII characters. 您需要遵循第二个链接中提供的编码,其中必须为ASCII字符。

The error code can be traced using the following code snippet from tweepy's init .py 可以使用tweepy的init .py中的以下代码片段来跟踪错误代码。

Looking at line #275, it's raised internally by tweepy because: 查看第275行,它在内部由tweepy引发,因为:

The HTTP request entity-header includes the "Content-Type" header field set to "application/x-www-form-urlencoded". HTTP请求实体标头包含设置为“ application / x-www-form-urlencoded”的“ Content-Type”标头字段。

You can obtain more information about this through Forms in HTML documents . 您可以通过HTML文档中的“表单”获得有关此信息的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM