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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:06:20+00:00 2026-06-06T17:06:20+00:00

I am building a python based web server ( Yes, python is a bad

  • 0

I am building a python based web server ( Yes, python is a bad choice for web server, but this is the only choice I have There is another great choice for my purpose, e.g. PHP, but I am restricted to python )

I use ProtoVis for some data visualization. (a JavaScript based visualization tool)

The following piece of code works if I just copy and paste them into a test file and rename .html (provided that I have the protovis library extracted beside it)

If you want to try, get it here https://github.com/mbostock/protovis/zipball/v3.3.1

<html>
    <head>
        <title>Area Chart</title>
        <link type="text/css" rel="stylesheet" href="ex.css?3.2"/>
        <script type="text/javascript" src="protovis/protovis.js"></script>
        <style type="text/css">
        #fig {
            width: 430px;
            height: 225px;
        }
        </style>
    </head>
    <body>
    <div id="center">
    <div id="fig">
    <script type="text/javascript+protovis">
    
var data = pv.range(0, 10, .1).map(function(x) {
    return {x: x, y: Math.sin(x) + Math.random() * .5 + 2};
  });
    
/* Sizing and scales. */
var w = 400,
    h = 200,
    x = pv.Scale.linear(data, function(d) d.x).range(0, w),
    y = pv.Scale.linear(0, 4).range(0, h);

/* The root panel. */
var vis = new pv.Panel()
    .width(w)
    .height(h)
    .bottom(20)
    .left(20)
    .right(10)
    .top(5);

/* Y-axis and ticks. */
vis.add(pv.Rule)
    .data(y.ticks(5))
    .bottom(y)
    .strokeStyle(function(d) d ? "#eee" : "#000")
  .anchor("left").add(pv.Label)
    .text(y.tickFormat);

/* X-axis and ticks. */
vis.add(pv.Rule)
    .data(x.ticks())
    .visible(function(d) d)
    .left(x)
    .bottom(-5)
    .height(5)
  .anchor("bottom").add(pv.Label)
    .text(x.tickFormat);

/* The area with top line. */
vis.add(pv.Area)
    .data(data)
    .bottom(1)
    .left(function(d) x(d.x))
    .height(function(d) y(d.y))
    .fillStyle("rgb(121,173,210)")
  .anchor("top").add(pv.Line)
    .lineWidth(3);

vis.render();

    </script>
    </div>
    </div>
    </body>
</html>

However, if I return the above code in a baseHTTPserver, it does not seem to work. From my investigation, it seems that the library at "protovis/protovis.js" is not properly included.

if url[0] == "/chart":
    self.send_response(200)
    self.send_header("Content-type","text/html")
    self.end_headers()
    self.wfile.write(chart())
    return

where chart() function returns the lines above.

I am working under CentOS 6.2 with python 2.6, is there anything special I need to do in baseHTTPserver to include that javascript library that I am using? The same code worked fine with Apache + PHP where I simply echo them.

Any idea?

======================== Solution ========================

Unlike Apache+PHP, BaseHTTPServer will not just serve anything you put into that folder. You have to either do it yourself, as Matthew described, or serve protovis.js from a different server (could even be a SimpleHTTPServer running on a different port). – Vasiliy Faronov

See Matthew Adams’s instruction below

What I had to do to fix the problem was to add another method into do_GET() that handles the JavaScript file

if url[0] == "/protovis/protovis.js":
    f = open("protovis/protovis.js","rb")
    for each_line in f:
        self.wfile.write(each_line)
    return

which solves the problem.

Thank you all for the solution, I really appreciate it

  • 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-06T17:06:22+00:00Added an answer on June 6, 2026 at 5:06 pm

    Make sure that you are serving protovis/protovis.js using your BaseHTTPServer. Basically the browser will “see” the line <script type="text/javascript" src="protovis/protovis.js"></script> when it is reading the html output it gets, and then request that the server actually send the protovis/protovis.js file. I didn’t see the python code in that github download, so I can’t specifically show how to do this in the context of your code, but check out SimpleHTTPRequestHandler. Using that, you can add to the do_GET() method to have the server send protovis/protovis.js when it is requested (that is, when self.path is protovis/protovis.js).

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

Sidebar

Related Questions

I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing
Let's say you are building a Python-based web app that requires some workflow management
I am going to be building a Pylons-based web application. For this purpose, I'd
I am building a tile based app in Python using pyglet/openGL wherein I'll need
I am building an application in Python and I have my whole package. While
I'm building a Web2Py-based web application and am doing most of my development right
I am building a dating site in Django / Python. I have birthday dates
I'm building a rather large project, that basically consists of this: Server 1: Ice
I'm building a Smalltalk API to an XML-based web service. The XML service is
Currently I'm building quite a large app with flex4+robotlegs+as3signals+google app engine based on python.

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.