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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:49:31+00:00 2026-05-29T11:49:31+00:00

The sample code for a basic web server given by http://twistedmatrix.com/trac/ seems to increment

  • 0

The sample code for a basic web server given by http://twistedmatrix.com/trac/ seems to increment the request counter by two for each request, rather than by 1.

The code:

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")
        return "I am request #" + str(self.numberRequests) + "\n"

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

Looking at the code, it looks like you should be able to connect to the url http://localhost:8080 and see:

I am request #1

Then refresh the page and see:

I am request #2

However, I see:

I am request #3

When I refresh again, I see:

I am request #5

So, judging from the counter, the server appears to call the function “render_GET” twice for each request. I am running this on Windows 7 using Python 2.7. Any idea what could be going on or is this expected behavior?

Update: The code is working perfectly, it’s the browser that is being tricksy. Each page refresh, the browser sends a GET request for “/” and “/favicon.ico”, which accounts for the incrementing by 2, because the render_GET function actually is being called twice per page refresh.

  • 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-29T11:49:32+00:00Added an answer on May 29, 2026 at 11:49 am

    Browsers can behave in surprising ways. If you try printing the full request, you might find it is requesting “/” and also “favicon.ico”, for example.

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

Sidebar

Related Questions

I'm looking for a basic code samples of how to upload files to server
How can I verify that the server sending a HTTP request is who I
I have a simple text reading code for Visual Basic: Dim fileReader As String
Currently, I have some basic code to play a simple tone whenever a button
Does anyone knows where I can find tutorials and code samples, basic and advanced,
Sample code that shows how to create threads using MFC declares the thread function
Sample code: public class Service1 { public int Service1() { .... } } public
Sample code <asp:Repeater> <ItemTemplate> <asp:ListView DataSource=<%# Container.DataItem.Items %> ... /> <asp:DataPager .... /> </ItemTemplate>
In sample code, I have seen this: typedef enum Ename { Bob, Mary, John}
Searching for some sample code for converting a point in WGS84 coordinate system to

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.