We help IT Professionals succeed at work.

HTTP/1.1" 405 4 Error

nainil
nainil asked
on
752 Views
Last Modified: 2013-11-13
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

Comment
Watch Question

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

Author

Commented:
Through web browser:

http://localhost/term

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

Author

Commented:
@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?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Author

Commented:
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

Author

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

Appreciate your time and help

Commented:
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.

OR

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.