Questions tagged [python-unicode]

Python distinguishes between byte strings and unicode strings. *Decoding* transforms bytestrings to unicode; *encoding* transform unicode strings to bytes.

Python distinguishes between byte strings and unicode strings. Decoding transforms bytestrings to unicode; encoding transform unicode strings to bytes.

Remember: you decode your input to unicode, work with unicode, then encode unicode objects for output as bytes.

See the

1053 questions
0
votes
1 answer

Is there a better way to retrieve strings from Python subprocess pipes with unicode_literals?

Another question looked at how to pipe byte strings to subprocess.Popen's to stdin when using unicode_literals. How to fix an encoding migrating Python subprocess to unicode_literals?. The answer there fixed the problem and created a warning when…
tahoar
  • 1,788
  • 3
  • 20
  • 36
0
votes
1 answer

Print multilingual characters in Python3

im trying to sending a response to a web, with multilingual characters on python 3 but all the time, it comes this: "\\xd8\\xa7\\xd9\\x84\\xd9\\x82\\xd8\\xa7\\xd9\\x85\\xd9\\x88\\xd8\\xb3 \\xd8\\xa7\\xd9\\x84\\xd8\\xb9\\xd8\\xb1\\xd8\\xa8\\xd9\\x8a…
hidura
  • 681
  • 3
  • 11
  • 36
0
votes
1 answer

UnicodeEncodeError is occurring while extracting Twitter data

I am trying to extract tweets based on Hash-tag. Below is my Python Source Code import tweepy consumer_key = "##" consumer_secret = "##" access_key = "##" access_secret = "##" auth = tweepy.OAuthHandler(consumer_key,…
Jagadeesh
  • 407
  • 1
  • 4
  • 9
0
votes
3 answers

Python - 'ascii' codec can't encode character u'\xe9' in position 5: ordinal not in range(128)

I'm trying to run a quick Django application that pulls data from Google AdWords and exposes the names of accounts that are managed by an agency. When doing so, I get the following error: UnicodeEncodeError at /account-hierarchy/ 'ascii' codec…
daniel_c05
  • 11,438
  • 17
  • 60
  • 78
0
votes
2 answers

PyUnicodeUCS2_* error while importing VTK

I've run into a strange problem. I built VTK with python wrappings on cent os 6.5. On importing vtk it gives me PyUnicodeUCS2_* error. I checked python used for the build for unicode setting with sys.maxunicode. It is UCS4. I searched for this…
gaj
  • 317
  • 6
  • 20
0
votes
1 answer

Python Unicode error, 'ascii' codec can't encode character

I am getting the following error : UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 587: ordinal not in range(128) My code: import os from bs4 import BeautifulSoup do = dir_with_original_files =…
Simon Kiely
  • 5,880
  • 28
  • 94
  • 180
0
votes
1 answer

BeautifulSoup4: how to find a HTML element whose text contains an accented character?

I have this tag in my HTML code Open and another one: Prévu I use (soup is the HTML page) soup.find(text='Open') and it is found but when it comes to use soup.find(text='Prévu') I get no result (None object). The goal of…
dragonmnl
  • 14,578
  • 33
  • 84
  • 129
0
votes
1 answer

Print succeeds but logging module throws exception

I'm trying to log the contents of a file, but I get some funny behavior from the logging module (and not only that one). Here is the file contents: "Testing …" Testing å¨'æøöä "Testing å¨'æøöä" And here is how I open and log it: with codecs.open(f,…
some user
  • 337
  • 1
  • 6
  • 16
0
votes
2 answers

ouput in brower differs from output in terminal char>128 python3 apache2

Trying to print euro sign in browser: Prints successfully on terminal but not on browser Same behavior in python 2.7 and 3 : would prefer python 3.4 solution Browsers tested fire fox and opera: url localhost/cgi-bin/test2.py Browser shows page…
Fredo
  • 27
  • 3
0
votes
0 answers

UnicodeDecodeError: 'utf8' codec can't decode byte 0xdf in position 2

I had written a source code to derive performance of stocks. It is running in an instance efficiently but showing "UnicodeDecodeError" while running in my local. I reffered this python: UnicodeDecodeError: 'utf8' codec can't decode byte 0xc0 in…
V Manikandan
  • 370
  • 6
  • 24
0
votes
1 answer

Python - Convert unicode hex to string

I am using Readability Parser API to extract content from a web page. It is ok when the web page is in Latin character set, but when I extract article in Cyrillic, it ends up with the…
nickbusted
  • 1,029
  • 4
  • 18
  • 30
0
votes
1 answer

Properly sorting lists of objects by attribute, with a twist

Assume I have a class called Subject: class Subject(): def __init__(self, name, longName): self.name = name self.long_name = longName def __repr__(self): return self.long_name + "(" + self.name + ")" In my code, I…
Peter W.
  • 2,323
  • 4
  • 22
  • 42
0
votes
1 answer

UnicodeEncode Error while running a python script

I wrote the following python script for retrieving the information from Yahoo Finance website and store it in a file. Following is the script: import urllib.request from bs4 import BeautifulSoup in_data =…
Darshil Babel
  • 145
  • 2
  • 13
0
votes
1 answer

Python unicode excape underscore and double quotes

I have data which represent usernames from different languages. I have carries out proper unicoding process as follows: while attempts < 3 and not success: query = ur'''select gu_name from globaluser where gu_name =…
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
0
votes
1 answer

Replace Character For All Rows using SQLAlchemy on Flask

I made the mistake of accidentally using non-ascii characters in a form that was submitted into a database using SQLAlchemy, running on Flask. Basically, rather than using the ASCII hyphen –, I used the unicode en-dash –. I am trying to now go…
Jason B
  • 7,097
  • 8
  • 38
  • 49