简体   繁体   中英

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 ...

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

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.

The error code can be traced using the following code snippet from tweepy's init .py

Looking at line #275, it's raised internally by tweepy because:

The HTTP request entity-header includes the "Content-Type" header field set to "application/x-www-form-urlencoded".

You can obtain more information about this through Forms in HTML documents .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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