Avatar of nainil
nainil
Flag for United States of America asked on

HTTP/1.1" 405 4 Error

Hello,

I am trying to replicate the source code from
https://code.launchpad.net/~keyvan/fivefilters/term-extraction/

I have the following:
WAMP
Python 2.7
MOD_WSGI
WEB.PY

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?

#!/home/protected/bin/python

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.remove(list[i])
			else:
				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) + ')'
		else:
			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.run()

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

Open in new window

ProgrammingPython

Avatar of undefined
Last Comment
BigRat

8/22/2022 - Mon
BigRat

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

ASKER
Through web browser:

http://localhost/term
BigRat

Sorry about that, is the URL available on the web, because the error is related to the browser possibly sending the wrong code.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
nainil

ASKER
@bigRat:
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?
ASKER CERTIFIED SOLUTION
BigRat

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
nainil

ASKER
Ill check on the sniffers.

Till then, Is it possible for you to download / execute the source code and advise?
http://www.sendspace.com/file/qbdgbi

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

Any help is appreciated
nainil

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


http://localhost/terms

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
context=Inevitably%2C+then%2C+corporations+do+not+restrict+themselves+merely+to+the+arena+of+economics.+Rather%2C+as+John+Dewey+observed%2C+%22politics+is+the+shadow+cast+on+society+by+big+business%22.+Over+decades%2C+corporations+have+worked+together+to+ensure+that+the+choices+offered+by+%27representative+democracy%27+all+represent+their+greed+for+maximised+profits.%0D%0A%0D%0AThis+is+a+sensitive+task.+We+do+not+live+in+a+totalitarian+society+-+the+public+potentially+has+enormous+power+to+interfere.+The+goal%2C+then%2C+is+to+persuade+the+public+that+corporate-sponsored+political+choice+is+meaningful%2C+that+it+makes+a+difference.+The+task+of+politicians+at+all+points+of+the+supposed+%27spectrum%27+is+to+appear+passionately+principled+while+participating+in+what+is+essentially+a+charade.&callback=
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
nainil

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

Appreciate your time and help
BigRat

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.