Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:51:02+00:00 2026-06-10T03:51:02+00:00

# -*- coding: utf-8 -*- from pyquery import PyQuery as pq from urllib import

  • 0
# -*- coding: utf-8 -*-
from pyquery import PyQuery as pq
from urllib import urlencode
from urllib2 import Request,urlopen
    def sendRequest(url, data = None, headersOnly = False):
    headers  = { 'User-Agent' : 'Mozilla/5.0 (X11; U; Linux i686; en-US;)' }
    request  = Request(url, data, headers)
    return urlopen(request).read()

resp = sendRequest("https://foursquare.com/v/rivers-edge-cafe--    morrison/4c1907776e02b7132eae627b")
print pq(resp)("#venueCategories").text()

Output should be Café, Burger Joint, Sandwich Place
but got exception:

Traceback (most recent call last):
  File "unicodeerr1.py", line 11, in <module>
    print pq(resp)("#venueCategories").text()
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 3: ordinal not in range(128)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:51:04+00:00Added an answer on June 10, 2026 at 3:51 am

    You need to specify an encoding for your source code, or use a character escape instead.

    # -*- coding: utf-8 -*-
    

    or

    print 'caf\xc3\xa9' # UTF-8 representation of e accent egu.
    

    You probably want to use a Unicode literal though (here with a unicode escape character):

    print u'caf\u00e9'
    

    Please do read the Unicode HOWTO to fully understand what goes on here. Other helpful documents:

    • Joel Spolsky’s The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
    • Ned Batchelder’s Pragmatic Unicode presentation.

    Note that your specific error doesn’t have anything to do with python 2.5 vs. 2.7, but everything with the output encoding of whatever you are printing to. On your server with python2.5, there is either no encoding specified or it is explicitly set to ASCII, but on your local machine with python 2.7, you are most likely dealing with a terminal that supports UTF-8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code here: # coding:utf-8 if __name__ == '__main__': from urllib2 import urlopen url
from django.utils.simplejson import dumps, loads # -*- coding: utf-8 -*- def index(request): return render_to_response('test2/index.html')
Example code: # -*- coding: utf-8 -*- from functools import wraps class MyClass(object): def
# -*- coding: utf-8 -*- # -*- coding: iso-8859-9 -*- import urllib2 import urllib
#!/usr/bin/env python # -*- coding: utf-8 -*- from sqlalchemy import create_engine connection = create_engine('mysql://user:passwd@localhost:3306/db').connect()
I have mail.py file: # coding: utf-8 from ..lib.common import * from ..lib.common import
this is my script # -*- coding: utf-8 -*- from BeautifulSoup import BeautifulSoup import
I made this python script: # -*- coding: utf-8 -*- from datetime import datetime
I have a script like this: #!/Python26/ # -*- coding: utf-8 -*- import sys
# -*- coding: utf-8 -*- def present_unicode(list): for a in list: print u%s %

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.