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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:28:04+00:00 2026-05-22T19:28:04+00:00

I am having a hard time trying to modify the Flask request object before

  • 0

I am having a hard time trying to modify the Flask request object before routing occurs.

My API Module (not my entire Flask app) depends on faking PUT and DELETE operations by sending a special header. I need to check out the contents of the “-Method” header and modify the Flask Request object accordingly, before Flask does its routing.

This is the short, pythonic, explicit code I’d like to work:

@api.before_request
def method_scrubbing():
    if request.headers.has_key('-Method'):
        method = request.headers['-Method'].upper()
        tagalog.log("in before_request, -Method = {}".format(method), 'force')
        if method not in ['PUT', 'DELETE']:
            raise ApiMethodException(method)
        else:
            request.method = method

…but I get a “read only property” error from werkzeug: http://drktd.com/74yk

I’ve seem Armin’s post at http://flask.pocoo.org/snippets/38/ but this appears to be app-wide (not specific to a module).

  • 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-22T19:28:05+00:00Added an answer on May 22, 2026 at 7:28 pm

    Werkzeug has the assumption that the request is only modified in a WSGI middleware or before Werkzeug has access to the data. The reason is that this way Werkzeug does not have to monitor the WSGI environment to see if it would have to invalidate caches or change behavior.

    In this particular case you might be successful however if you are carefully by modifying the underlying WSGI environment:

    request.environ['REQUEST_METHOD'] = 'something'
    

    After that request.method should show “something” and the behavior should change to form parsing. I have not tried this and don’t know if it will work. Personally I would write a middleware that does the rewriting for the whole application or does some simple url prefix matching for that behavior probably.

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

Sidebar

Related Questions

I'm having hard time trying to figure out how to auto-save user data in
I've been having a hard time trying to understand PyPy's translation. It looks like
I'm having a hard time trying to get my team comfortable with interface based
I'm having a hard time trying to make a Java program with just a
For some reason, I'm having a hard time trying to cover the block of
I am having one heck of a hard time trying to figure this out.
I'm having a hard time trying to find a rotator to fit my needs
I'm new to iPhone development, and been having a hard time trying to figure
I'm having a hard time trying to figure this out. Say I have the
I am having a hard time trying to change the width of my h:outputLabel,

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.