We help IT Professionals succeed at work.

HTTP/1.1" 405 4 Error

nainil asked
Last Modified: 2013-11-13

I am trying to replicate the source code from

I have the following:
Python 2.7

When I try to execute the below code the Apache access logs say it's an HTTP/1.1" 405 4 Error, however the page output says "None". This is the first time we are trying to use Python code. What are we doing wrong?


import web

urls = (
    '/', 'hello',
	'/terms', 'terms'
app = web.application(urls, globals())

class hello:
    def GET(self):
        return '<form action="terms" method="POST"><textarea name="context" style="width:450px; height:300px;">Inevitably, then, corporations do not restrict themselves merely to the arena of economics. Rather, as John Dewey observed, "politics is the shadow cast on society by big business". Over decades, corporations have worked together to ensure that the choices offered by \'representative democracy\' all represent their greed for maximised profits.\n\nThis is a sensitive task. We do not live in a totalitarian society - the public potentially has enormous power to interfere. The goal, then, is to persuade the public that corporate-sponsored political choice is meaningful, that it makes a difference. The task of politicians at all points of the supposed \'spectrum\' is to appear passionately principled while participating in what is essentially a charade.</textarea><br />JSON callback: <input type="text" name="callback" /><br /><input type="submit" value="Get terms" /></form>'

class terms:
    def POST(self):
		import re
		import simplejson as json
		from topia.termextract import extract
		extractor = extract.TermExtractor()
		#extractor.filter = extract.permissiveFilter
		extractor.filter = extract.DefaultFilter(singleStrengthMinOccur=1)
		def term_compare(x, y):
			if y[1]+y[2]*2 > x[1]+x[2]*2:
				return 1
			elif y[1]==x[1] and y[2]==x[2]:
				return 0
			else: # x<y
				return -1
		input = web.input(callback=None)
		content = input.context.lower()
		content = content.replace(u"\u201c", '"').replace(u"\u201d", '"').replace(u"\u2018", "'").replace(u"\u2019", "'").replace(u"\u2026", "")
		list = sorted(extractor(content), term_compare)
		list = list[:50]
		for i in range(len(list)-1, -1, -1):
			if len(list[i][0]) == 1 or list[i][2] > 2 or (list[i][0].find("http") >= 0) or not re.search('[a-z]', list[i][0]) or re.search('[0-9]', list[i][0]):
				list[i] = list[i][0]
		callback = input.callback
		if callback and re.match('^[a-zA-Z0-9._\[\]]+$', callback):
			return callback + '(' + json.dumps(list, indent=4) + ')'
			return json.dumps(list, indent=4)
		#return json.dumps(list, indent=4)
		#return json.dumps(extractor(i.context).sort(term_compare))

if __name__ == "__main__":

app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc()

Open in new window

Watch Question

How are you actually calling this page, since a 405 means HTTP Method not allowed.


Through web browser:


Sorry about that, is the URL available on the web, because the error is related to the browser possibly sending the wrong code.


Unfortunately it is not configured on our production environment which is available online.

Is there any tool you can suggest to us to debug what is being sent and can generate logs which we can post here for you to look at?
This one is on us!
(Get your first solution completely free - no credit card required)


Ill check on the sniffers.

Till then, Is it possible for you to download / execute the source code and advise?

Sorry, the EE uploader was not recognizing .py files, hence had to use a third party service.

Any help is appreciated


This is what I have captured so far. Please advise if something looks wrong.


POST /terms HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://localhost/terms
Content-Type: application/x-www-form-urlencoded
Content-Length: 808
HTTP/1.1 405 Method Not Allowed
Date: Wed, 25 May 2011 15:31:42 GMT
Server: Apache/2.2.11 (Win32) PHP/5.3.0 mod_wsgi/3.3 Python/2.7.1
Allow: GET
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html


Well, I have been able to execute the script from command line... Guess we are all set.

Appreciate your time and help

Sorry, I was away for a day and forgot. There is nothing wrong with the above post. I suspect that the configuration in Apahce is wrong. It normally looks for cgi-bin when a post comes in, but you also have mod_wsgi to configure. If you post your httpd.conf I'll take a look for you.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.