I had problem taking an RSS feed date and dropping it into a database.
This put together by Dave Warry for me:
from datetime import datetime # I love classes named after their parent module
original_date = "Thu, Apr 15 2010 08:14:15 GMT"
# formatting/parsing details are in here:
# http://docs.python.org/library/datetime.html#strftime-strptime-behavior
dt = datetime.strptime(original_date, "%a, %b %d %Y %H:%M:%S %Z")
desired_date = dt.strftime("%Y-%m-%d %H:%M:%S")
Search This Blog
Code snippets and memory joggers
Tuesday, April 20, 2010
bad u'\u2019' character in python: UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019' in position :
lifted from Neil Rubens's blog
Submitted by Neil on Sat, 01/16/2010 - 18:13
bad u'\u2019' character in python: UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019' in position : ordinal
Problem: UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019' in position : ordinal not in range(256)
Sollution:
if val != None and type(val) == type(u"") and val.find(u'\u2019') >= 0 : val = val.replace(u'\u2019', '\'')
Keywords
mysql UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019'
\u2019
Submitted by Neil on Sat, 01/16/2010 - 18:13
bad u'\u2019' character in python: UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019' in position : ordinal
Problem: UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019' in position : ordinal not in range(256)
Sollution:
if val != None and type(val) == type(u"") and val.find(u'\u2019') >= 0 : val = val.replace(u'\u2019', '\'')
Keywords
mysql UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019'
\u2019
Subscribe to:
Posts (Atom)
About Me
- Keith
- I love to travel and meet new people, motorbikes, moving my body through dance, martial arts and yoga. I'm a lifelong learner interested in how things work, and the way people think and make their decisions. My choice of superpower would be to speak with someone and understand them completely, including their intention and for me to be able to communicate my intention to them clearly in their own language. As an Amazon Associate, I may earn from links to qualifying purchases.