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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:41:16+00:00 2026-05-24T18:41:16+00:00

I am recreating a service in Python/Flask and am running into an issue with

  • 0

I am recreating a service in Python/Flask and am running into an issue with the way the existing clients authenticate. I have to match the existing clients scheme for compatibility reasons.

The existing clients take the username, password and base64 encode it. This is not HTTP Basic Authentication, despite sounding similar. Below is some sample code that would create this login request.

credentials = {
            'username': 'test@example.com',
            'password': 'password'
}
data = b64encode(urlencode(credentials))
request = urllib2.Request(loginURL)
request.add_data(data)
# request.add_header('Content-Type', 'application/gooblygop')
# 'application/x-www-form-urlencoded' seems to be a default Content-Type
login = urllib2.urlopen(request)

On the server side, I take the POST data and base64 decode it to get the username and password information again.

flask server:
@app.route('/login', methods=['POST'])
def login():
    error = None
    if request.method == 'POST':
        # post data: cGFzc3dvcmQ9ZGVmYXVsdCZlbWFpbD10ZXN0JTQwZXhhbXBsZS5jb20=
        data = b64decode(request.data)
        # decoded data: password=default&email=test%40example.com
        return('ok')

The problem is the Content Type. If I specify an unknown Content-Type in the client (application/gooblygop), Flask exposes the POST data to request.data and I can decode the base64 string. If I leave the Content-Type as default (application/x-www-form-urlencoded), the raw data is not exposed to request.data and I don’t know how to retrieve the base64 encoded string and make use of it.

The existing client software all pretty much defaults to x-www-form-urlencoded, but I can’t rely on that always being the case.

Essentially, I need a reliable, server-side method for accessing that encoded string no matter what Content-Type the client program states.

Other notes: I am very new to Python, coming from a PHP background. So I am very open to suggestions. Also, this project is primarily for personal use.

  • 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-24T18:41:17+00:00Added an answer on May 24, 2026 at 6:41 pm

    You want to look at the request.form object when dealing with urlencoded posts with normal mimetypes. In this case you have an unusual form, but here is a way to do it:

    # mkreq.py
    from urllib import urlencode
    import urllib2
    from base64 import b64encode
    
    credentials = {
                'username': 'test@example.com',
                'password': 'password'
    }
    data = b64encode(urlencode(credentials))
    request = urllib2.Request("http://localhost:5000/login")
    request.add_data(data)
    request.add_header('Content-Type', 'application/gooblygop')
    # 'application/x-www-form-urlencoded' seems to be a default Content-Type
    login1 = urllib2.urlopen(request).read()
    print(login1)
    request2 = urllib2.Request("http://localhost:5000/login")
    request2.add_data(data)
    login2 = urllib2.urlopen(request2).read()
    print(login2)
    

    You probably want to modify the login bit to check the mimetype, here is a version with minimal changes to your current setup:

    @app.route('/login', methods=['POST'])
    def login():
        error = None
        if request.method == 'POST':
            # post data: cGFzc3dvcmQ9ZGVmYXVsdCZlbWFpbD10ZXN0JTQwZXhhbXBsZS5jb20=
            data = b64decode(request.data)
            # decoded data: password=default&email=test%40example.com
            if not data:
                data = b64decode(request.form.keys()[0])
            special_mimetype = request.mimetype
            return(special_mimetype + '\n' + data)
    

    This is the output of the first code sample, with two requests:

    bvm$ python mkreq.py
    application/gooblygop
    username=test%40example.com&password=password
    application/x-www-form-urlencoded
    username=test%40example.com&password=password
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a WCF service up and running on a server. We have a
I have a WCF service that I consume in my code and generated as
I have a web service that exposes operations to and from a database. I'm
We have a concrete singleton service which implements Ninject.IInitializable and 2 interfaces. Problem is
I have a web service that serves a javascript source file to browsers. The
I have a windows service written in c#. It has a timer inside, which
It seems that I have an issue with encoding. The field max width is
I have an Activity that holds a ServiceConnection to a Service. When the orientation
I have a custom employee object in the web service as a type. It
I am running IIS7 on Windows 7 Pro. I have a VS2010 solution from

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.