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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:36:02+00:00 2026-06-10T09:36:02+00:00

I am running the following code; it is from the Twisted Framework’s example list

  • 0

I am running the following code; it is from the Twisted Framework’s example list and is of a webserver.

from twisted.web import server, resource
from twisted.internet import reactor

class HelloResource(resource.Resource):
    isLeaf = True
    numberRequests = 0

    def render_GET(self, request):
        self.numberRequests += 1
        request.setHeader("content-type", "text/plain")
        arg = request.args
        q = arg['q']

        #Added for debugging
        for key, value in arg.iteritems():
            print key, value

        return "I am request #" + str(self.numberRequests) + " " + q[0] + "\n"

reactor.listenTCP(8080, server.Site(HelloResource()))
reactor.run()

To execute:

[user@localhost pytwist]$ python twi.py

Browser URL:

http://localhost:8080/?q=test

However, I am getting the following KeyError Exception on the console:

File "twi.py", line 12, in render_GET
q = arg['q']
exceptions.KeyError: 'q'

Yet, the browser is giving expected output:

I am request #3 test

Also, the console is properly displaying the debug part of the code:

q ['af']

If the output is correct and the key exists properly, then what could be the error? Note that I have tried dict.get() method but the problem persists.

  • 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-10T09:36:03+00:00Added an answer on June 10, 2026 at 9:36 am

    It’s probably because your browser is making two requests. The second request is probably for the favicon.ico file, and here it doesn’t send the q parameter.

    Try printing the URL requested.

    Related

    • the sample python twisted event driven web application increments request count by 2, why?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running the following example code from Apple - NSString *requestURL = [[NSString alloc]
So I'm running the following code from the command line python: import logging rootLog
I'm getting the error message when running the following code from a C# console
I am running following code to create bmp image from pdf using Ghost4j i
I'm running the following code to get a random entry from a dictionary: SELECT
I'm running the following code: new FileSystemXmlApplicationContext(/data/farm/Server/confData/1000004/contex.xml) and it throws java.io.FileNotFoundException: class path resource
I'm running the following code in PHP to generate the random list of movies
I have the following code (almost an exact copy of the Chat server example
Following example code from the libpcap documentation yields the following code which should report
I'm running the following code from the command line (python filename.py) and it wont

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.