How to install Pynma & Twython twitter.updateStatusWithMedia UnicodeDecodeError - python

1st Q is how do i install pynma modules?,where should i put the modules? Im new in Python because usually there is setup.py, but pynma do not have setup.py :( im trying to implement notify my android in raspberry pi and im lost .. https://github.com/uskr/pynma
2nd Q is im having problem with Twython updateStatusWithMedia, but with updateStatus it just fine, i can tweet normal message.
here is my code
from twython import Twython
twitter = Twython(
twitter_token = '52IKIxxxx',
twitter_secret = 'SvwK4xmxxxx',
oauth_token = '5164xxxxxxx',
oauth_token_secret = 'kVkrHxxxxxx'
)
twitter.updateStatus(status='hello tweet from raspberry pi 1.47am')
twitter.updateStatusWithMedia("/home/pi/teddy.jpg", status='hello!')
'ascii' codec can't decode byte 0xff in position 247: ordinal not in range(128)
'ascii' codec can't decode byte 0xff in position 247: ordinal not in range(128)
'ascii' codec can't decode byte 0xff in position 247: ordinal not in range(128)
here is the image of the error
forgive my english :(

Twython (as of 2.9.0) has the updateStatusWithMedia bug fixed. It was an issue with a library upstream that we depend on, but things should be good now. Hope it works out for you, sorry about the delay!

Related

How to decode python byte code to ASCII? (Selenium. Getting xml from network response)

How to decode pyhon bytecode to ascii?
I extract data with selenium from network response. Should get xml.
Getting: ['b'\xa5\xff\xff\xc7\x88\xe4\xb4\xd7\x03\xa0\x11:|\xce\xdb\xb7\x0f\xf1\xdf\xfc\x1f\xdb\x93\x91^\xbc\xa3\xdd\xc2\x02V\x00\xba$\xbd\x10\xd2\xd0E\xf2\x90\xb6\xca\xee\x10\xbf\xbf_\xbf\xfc\xef?\xe9\x13{H\xf1\xa1\xa0\x00\x1c\x01(\x80\x1c\x81\x02(s\xe7Z\xf3\xb3N\xf5L\xdc>\xe7\x8f\xbbwl\xbf\x99\x91\xd4O\xde\xb4,\xf3PH\x02L1\x00\xc98\xc3,\x13!\x82\xc6\xc2\xa6Bd"k\xcb\x9d(\xb9\x13%WQr\x15%W\xb1\xe5J\t\x9e:\x8a\x03\x99\x06H\xd0\x8f\xd8\xfe\x9f9\xbc\xfc\x157\x111\xd7\x15\xaab\xfb\xe8;\xab\xee\xfc\x9b\xeeu\x10<d\x04\x06Y\xa8\xd7\x9f\x11...
Code:
...
for request in driver.requests: if request.response: text_file.write(str(request.response.body))
I've tried:
decoded = request.response.body.decode('ascii')
or request.response.body.decode('utf-8') or cp1251/1252
I get:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa5 in position 0: ordinal not in range(128)
Response should be xml (~1,5mb) in attached photoresponse
If I use:
decoded = base64.b64decode(request.response.body)
I'm getting smth like: b'T#\x00\xad\x9a\xb5\xba\xfa3u\xca\x84PG\xbd\x8a\xab\x1f\xcdcJ%\r\xd4\xff\x0c$)\x9a>.... not what to be expected.
Combining decoded = base64.b64decode(request.response.body).decode('ascii') also doesnt help:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x85 in position 0: ordinal not in range(128)
Help me, please.
Its because of the Header 'Content-Encoding': 'br'
Installing brotly helped. Also deleting
This message helped a lot

How to fix UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d : character maps to <undefined>?

I am using curl to data.
import os
cmd = "curl --data \"action=getdata\" https:localhost:8070"
print(cmd)
data = os.popen(cmd).read()
The line above produces an error UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 565334: character maps to <undefined>.
When I debugged using breakpoints, the command os.popen generates a large corpus of text and when it goes to read() the error arises in file cp1252.py in IncrementalDecoder class. I tried doing,
data = os.popen(cmd).read().encode('utf-8').decode('ascii')
and
data = os.popen(cmd).read().encode().decode('utf-8')
But the error persists. How can we solve this?

RobotFramework 'ASCII' codec can't decode byte 0xd7 in position 1: Ordinal not in range(128)

I use Robot Framework with ride to do python-auto-test, but I got this problem in Robot Framework console:
"FAILED D:\eclipse\oppoAutoTest\AutoTest\../../PyAutoTest/src/testTcardCopy.py
FAILED D:\eclipse\oppoAutoTest\AutoTest\commonUserKeyWords\../../../PyAutoTest/src/testMkDir.py
FAILED ../../PyAutoTest/basic/testSwipeScreen.py 'ascii' codec can't decode byte 0xd7 in position 1: ordinal not in range(128)"
Can you help me ?
This is my Robot Framework code:
*** Settings ***
Library
../../eclipse_workplace_java/PyAutoTest/src/testTcardCopy.py
Resource commonUserKeyWords/BASIC.tsv
Resource commonUserKeyWords/CAMERA.tsv
*** Test Cases ***
bspTcardTest
${test_v_file_dir_path} set Variable /storage/sdcard0/tmp
${test_v_file_dir_ifexitd_result} ${test_v_file_dir_if_success}
${test_v_file_dir_stdout} ${test_v_file_dir_stdout_mount} 判断文件或文件
夹是否存在 ${test_v_file_dir_path}
log ${test_v_file_dir_ifexitd_result}
log ${test_v_file_dir_if_success}
log ${test_v_file_dir_stdout}
log ${test_v_file_dir_stdout_mount}
Should_Be_True '${test_v_file_dir_if_success}'=='True'
My python code also has utf-8:
# coding=utf-8

Decoding error with Python 3.6

I've been dealing with Landlab and Python for little time, so I'm not an expert user. I was trying to run a model which purpose is to import an existing DEM into a grid, but it didn't work out.
This is the code:
from landlab import RasterModelGrid
from landlab.io import read_esri_ascii
mg = RasterModelGrid((4852, 7894), 40)
z = mg.add_zeros('node', 'elevation')
(mg, z) = read_esri_ascii('DEM40_Sicilia_only_landlab.asc',name='elevation')
It gave me this error:
File "C:\Users\claudio\Anaconda3\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 202: character maps to <undefined>
Does anyone know the answer to solve my problem?

Anyone know how to fix a unicode error?

I am using Google App Engine for Python, but I get a unicode error is there a way to work around it?
Here is my code:
def get(self):
contents = db.GqlQuery("SELECT * FROM Content ORDER BY created DESC")
output = StringIO.StringIO()
with zipfile.ZipFile(output, 'w') as myzip:
for content in contents:
if content.code:
code=content.code
else:
code=content.code2
myzip.writestr("udacity_code", code)
self.response.headers["Content-Type"] = "application/zip"
self.response.headers['Content-Disposition'] = "attachment; filename=test.zip"
self.response.out.write(output.getvalue())
I now get a unicode error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf7 in position 12: ordinal not in range(128)
I believe it is coming from output.getvalue()... Is there a way to fix this?
#Areke Ignacio's answer is the fix. For a brief walkthrough here is a post I did recently "Python and Unicode Punjabi" https://www.pippallabs.com/blog/python-and-unicode-panjabi
I had the exact same issue.
in the end I solved it by changing the call to writestr from
myzip.writestr("udacity_code", code)
to
myzip.writestr("udacity_code", code.encode('utf-8'))
From this link:
Python UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 ordinal not in range(128)
However in the meantime your problem is that your templates are ASCII
but your data is not (can't tell if it's utf-8 or unicode). Easy
solution is to prefix each template string with u to make it Unicode.

Categories