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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:01:05+00:00 2026-06-14T11:01:05+00:00

I am trying to write a python web app that will take some sql

  • 0

I am trying to write a python web app that will take some sql and a bunch of other things and return a Json file, the latter part is not the issue and I have not even put it in the script yet, the issue is that the url being passed is being utf-8 encoded and then url encoded

turning our example

query :SELECT + ;
test: 2

into

test=2&query=SELECT+%2B+%3B

This seems to be ok

but the receiving get seems to think that it can expand the codes back into chars

and it receives

test=2&query=SELECT+++;

then this is url decoded and it chops off the semicolon, and i want to keep the semicolon!
it also turns the +’s which are rightly spaces into spaces but the previous bug made the real plus code into a literal plus which turns it into a space!

{'test': '2', 'query': 'SELECT   '}

code is as follows:

#!/usr/bin/python

import web
import psycopg2
import re
import urllib
import urlparse

urls = (
    '/query', 'query',
    '/data/(.*)', 'data'
)

app = web.application(urls, globals())
render = web.template.render('templates/')

class query:
    def GET(self):
        return render.query()

    def POST(self):
        i = web.input()
        data = {}
        data['query'] = i.sql.encode('utf-8')
        data['test'] = '2'

        murl = urllib.urlencode(data)
        return "<a href=\"http://localhost:8080/data/"+murl+"\">go!</a>"

class data:
    def GET(self, urlEncodedDict):

        print "raw type:", type(urlEncodedDict)
        print "raw:", urlEncodedDict

        urlEncodedDict = urlEncodedDict.encode('ascii', 'ignore')
        print "ascii type:", type(urlEncodedDict)
        print "ascii:", urlEncodedDict

        data = dict(urlparse.parse_qsl(urlEncodedDict, 1))    #bad bit
        print "dict:", data
        print "element:", data['query']

        if ( re.match('SELECT [^;]+ ;', data['query'])):
            return 'good::'+data['query']
        else:
            return 'Bad::'+data['query']


if __name__ == "__main__":
    app.run()

Url generated from my test form is:

http://localhost:8080/data/test=2&query=SELECT+%2B+%3B

Output is as follows:

raw type: <type 'unicode'>
raw: test=2&query=SELECT+++;
ascii type: <type 'str'>
ascii: test=2&query=SELECT+++;
dict: {'test': '2', 'query': 'SELECT   '}
element: SELECT   
127.0.0.1:53272 - - [16/Nov/2012 11:05:44] "HTTP/1.1 GET /data/test=2&query=SELECT+++;" - 200 OK
127.0.0.1:53272 - - [16/Nov/2012 11:05:44] "HTTP/1.1 GET /favicon.ico" - 404 Not Found

I wish to get the same dict out of the get that i encode in the first place.

  • 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-14T11:01:06+00:00Added an answer on June 14, 2026 at 11:01 am

    If you want to pass data into a GET request, you need to use the query string syntax using the question mark character [?] as a delimiter.

    The URL should be:

    http://localhost:8080/data/?test=2&query=SELECT+%2B+%3B
    

    After that, you just have to use web.input() to get a dictionary with all arguments already decoded.

    urls = (
        '/query', 'query',
        '/data/', 'data'
    )
    
    [...] 
    
    class data:
        def GET(self):
            data = web.input()
            print "dict:", data
            print "element:", data['query']
    
            if ( re.match('SELECT [^;]+ ;', data['query'])):
                return 'good::'+data['query']
            else:
                return 'Bad::'+data['query']
    

    Result:

    dict: <Storage {'test': u'2', 'query': u'SELECT + ;'}>
    element: SELECT + ;
    127.0.0.1:44761 - - [16/Nov/2012 15:06:06] "HTTP/1.1 GET /data/" - 200 OK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a python script that will take a json object
I'm trying to write some Python code that will establish an invisible relay between
I'm trying to write a python regular expression that will match both these URLs:
I am trying to write a python script that will change my cwd to
I'm trying to make a web app that will manage my Mercurial repositories for
I'm trying to write a python web scraper that takes a pandora account and
I am just trying to write a small web page that can parse some
I'm trying to write a Python script that uses a particular external application belonging
I am trying to write a python script that takes record data like this
I'm trying to write a Python C extension that processes byte strings, and I

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.