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 6643315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:02:12+00:00 2026-05-26T00:02:12+00:00

I am writing a Python web app and in it I plan to leverage

  • 0

I am writing a Python web app and in it I plan to leverage Wikipedia. When trying out some URL Fetching code I was able to fetch both Google and Facebook (via Google App Engine services), but when I attempted to fetch wikipedia.org, I received an exception. Can anyone confirm that Wikipedia does not accept these types of page requests? How can Wikipedia distinguish between me and a user?

Code snippet (it’s Python!):

    import os
import urllib2
from google.appengine.ext.webapp import template


class MainHandler(webapp.RequestHandler):
    def get(self):
        url = "http://wikipedia.org"
        try:
          result = urllib2.urlopen(url)
        except urllib2.URLError, e:
          result = 'ahh the sky is falling'
        template_values= {
            'test':result,
        }
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))
  • 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-05-26T00:02:13+00:00Added an answer on May 26, 2026 at 12:02 am

    urllib2 default user-agent is banned from wikipedia and it results in a 403 HTTP response.
    You should modify your application user-agent with something like this:

    #Option 1
    import urllib2
    opener = urllib2.build_opener()
    opener.addheaders = [('User-agent', 'MyUserAgent')]
    res= opener.open('http://whatsmyuseragent.com/')
    page = res.read()
    
    #Option 2
    import urllib2
    req = urllib2.Request('http://whatsmyuseragent.com/')
    req.add_header('User-agent', 'MyUserAgent')
    urllib2.urlopen(req)
    
    #Option 3
    req = urllib2.Request("http://whatsmyuseragent.com/", 
                           headers={"User-agent": "MyUserAgent"})
    urllib2.urlopen(req)
    

    Bonus link:
    High level Wikipedia Python Clients
    http://www.mediawiki.org/wiki/API:Client_code#Python

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

Sidebar

Related Questions

I'm writing a web-server in Python as a hobby project. The code is targeted
I'm writing a web app using python with web.py, and I want to implement
I'm writing a Python module that wraps out a certain web service API. It's
I'm writing a web app using Python and the web.py framework, and I need
I'm writing a web-app using Python and Pylons. I need a textbox that is
I am writing a simple Python web application that consists of several pages of
I'm writing a small web server in Python, using BaseHTTPServer and a custom subclass
I'm writing a web application in Python, intended for use by teachers and pupils
I am writing a web-framework for Python, of which the goal is to be
I'm writing a small web server for testing purposes using python, BasicHTTPServer and SimpleHTTPServer.

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.