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

  • Home
  • SEARCH
  • 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 3234312
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:22:37+00:00 2026-05-17T17:22:37+00:00

Using urllib2, are we able to use a method other than ‘GET’ or ‘POST’

  • 0

Using urllib2, are we able to use a method other than ‘GET’ or ‘POST’ (when data is provided)?

I dug into the library and it seems that the decision to use GET or POST is ‘conveniently’ tied to whether or not data is provided in the request.

For example, I want to interact with a CouchDB database which requires methods such as ‘DEL’, ‘PUT’. I want the handlers of urllib2, but need to make my own method calls.

I WOULD PREFER NOT to import 3rd party modules into my project, such as the CouchDB python api. So lets please not go down that road. My implementation must use the modules that ship with python 2.6. (My design spec requires the use of a barebones PortablePython distribution). I would write my own interface using httplib before importing external modules.

Thanks so much for the help

  • 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-17T17:22:37+00:00Added an answer on May 17, 2026 at 5:22 pm

    You could subclass urllib2.Request like so (untested)

    import urllib2
    
    class MyRequest(urllib2.Request):
        GET = 'get'
        POST = 'post'
        PUT = 'put'
        DELETE = 'delete'
    
        def __init__(self, url, data=None, headers={},
                     origin_req_host=None, unverifiable=False, method=None):
           urllib2.Request.__init__(self, url, data, headers, origin_req_host, unverifiable)
           self.method = method
    
        def get_method(self):
            if self.method:
                return self.method
    
            return urllib2.Request.get_method(self)
    
    opener = urllib2.build_opener(urllib2.HTTPHandler)
    req = MyRequest('http://yourwebsite.com/put/resource/', method=MyRequest.PUT)
    
    resp = opener.open(req)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get a requested host's ip address using urllib2 like: import urllib2
I'm using the urllib2.urlopen method to open a URL and fetch the markup of
I'm using my own resolver and would like to use urllib2 to just connect
I've setup a script to download an mp3 using urllib2 in Python. url =
Is it possible to inspect the attributes of an Python urllib2.Request (url, data, headers
I'm using Python Google App Engine to simply fetch html pages and show it.
I'm still relatively new to Python, so if this is an obvious question, I
I want to make a python script that tests the bandwidth of a connection.
They didn't mention this in python documentation. And recently I'm testing a website simply
I have a trusted remote server that stores many custom Python modules. I can

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.