Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79434 > unrolled thread

403 forbidden error

Started bydiyaraik@gmail.com
First post2014-10-22 04:36 -0700
Last post2014-10-26 22:56 -0700
Articles 6 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  403 forbidden error diyaraik@gmail.com - 2014-10-22 04:36 -0700
    Re: 403 forbidden error Chris Angelico <rosuav@gmail.com> - 2014-10-22 23:43 +1100
    Re: 403 forbidden error Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-22 08:50 -0400
    Re: 403 forbidden error Diya Rai <diyaraik@gmail.com> - 2014-10-26 22:12 -0700
      Re: 403 forbidden error Chris Angelico <rosuav@gmail.com> - 2014-10-27 16:34 +1100
        Re: 403 forbidden error Diya Rai <diyaraik@gmail.com> - 2014-10-26 22:56 -0700

#79434 — 403 forbidden error

Fromdiyaraik@gmail.com
Date2014-10-22 04:36 -0700
Subject403 forbidden error
Message-ID<82d4292e-10de-4d47-882e-bab75777fbfe@googlegroups.com>
Hai,

  Could anyone please help me to resolve 403 forbidden error while logging into an application.

Following is the error details:

Traceback (most recent call last):
  File "./example6.py", line 18, in <module>
    response = urllib2.urlopen(req)
  File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 406, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 444, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: FORBIDDEN


Sorry if the question is not relevant as im new to python.


Regards,
Diya

[toc] | [next] | [standalone]


#79439

FromChris Angelico <rosuav@gmail.com>
Date2014-10-22 23:43 +1100
Message-ID<mailman.15071.1413981812.18130.python-list@python.org>
In reply to#79434
On Wed, Oct 22, 2014 at 10:36 PM,  <diyaraik@gmail.com> wrote:
>   Could anyone please help me to resolve 403 forbidden error while logging into an application.

That comes down tot he server you're talking to. Maybe your
username/password is wrong, or maybe you need to send back a cookie,
or something. If you do some web searches, you should be able to find
some info about HTTP; the better you understand the protocol, the more
you'll understand of what urllib2 is saying.

ChrisA

[toc] | [prev] | [next] | [standalone]


#79440

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2014-10-22 08:50 -0400
Message-ID<mailman.15072.1413982224.18130.python-list@python.org>
In reply to#79434
On Wed, 22 Oct 2014 04:36:47 -0700 (PDT), diyaraik@gmail.com declaimed the
following:

>Hai,
>
>  Could anyone please help me to resolve 403 forbidden error while logging into an application.
>

http://en.wikipedia.org/wiki/HTTP_403

>
>Sorry if the question is not relevant as im new to python.
>

	Without the relevant code, there is nothing else to critique.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#79764

FromDiya Rai <diyaraik@gmail.com>
Date2014-10-26 22:12 -0700
Message-ID<04b6b33f-885e-4e4a-b458-b258b34fbb90@googlegroups.com>
In reply to#79434
On Wednesday, October 22, 2014 5:07:00 PM UTC+5:30, Diya Rai wrote:
> Hai,
> 
>   Could anyone please help me to resolve 403 forbidden error while logging into an application.
> 
> Following is the error details:
> 
> Traceback (most recent call last):
>   File "./example6.py", line 18, in <module>
>     response = urllib2.urlopen(req)
>   File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
>     return _opener.open(url, data, timeout)
>   File "/usr/lib/python2.7/urllib2.py", line 406, in open
>     response = meth(req, response)
>   File "/usr/lib/python2.7/urllib2.py", line 519, in http_response
>     'http', request, response, code, msg, hdrs)
>   File "/usr/lib/python2.7/urllib2.py", line 444, in error
>     return self._call_chain(*args)
>   File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
>     result = func(*args)
>   File "/usr/lib/python2.7/urllib2.py", line 527, in http_error_default
>     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
> urllib2.HTTPError: HTTP Error 403: FORBIDDEN
> 
> 
> Sorry if the question is not relevant as im new to python.
> 
> 
> Regards,
> Diya

Thanks Chris Angelico and Dennis Lee Bieber for replying.
Username and password is correct.
Its a simple login script.

import urllib
import httplib2

http = httplib2.Http()

url = 'http://localhost/login_ajax'   
body = {'email': 'xyz@google.com', 
        'password': '*******'}
headers = {'Content-type': 'application/x-www-form-urlencoded'}
response, content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
print response

This is the part of the code which im trying to execute. We are trying to load test a web application through python script, currently checking the login part.

Thanks in advance,
Diya

[toc] | [prev] | [next] | [standalone]


#79765

FromChris Angelico <rosuav@gmail.com>
Date2014-10-27 16:34 +1100
Message-ID<mailman.15226.1414388091.18130.python-list@python.org>
In reply to#79764
On Mon, Oct 27, 2014 at 4:12 PM, Diya Rai <diyaraik@gmail.com> wrote:
> This is the part of the code which im trying to execute. We are trying to load test a web application through python script, currently checking the login part.
>

Does it work when you log in using a web browser? If so, grab a
browser with debugging facilities (Firefox with Firebug, or Chrome
with its F12 box, or something), do the login, and have a look at
exactly what request headers are being sent. Then compare with what
your script is doing. Once you have the two side by side, you can
progressively work through it until you figure out which header makes
the difference - maybe your script isn't sending Host, or maybe you
need a cookie from a previous request, or maybe it's actually checking
the Referer and rejecting if it isn't right. Could be all sorts of
things.

Good luck! Might be a tedious job, or might be the first thing you try.

ChrisA

[toc] | [prev] | [next] | [standalone]


#79766

FromDiya Rai <diyaraik@gmail.com>
Date2014-10-26 22:56 -0700
Message-ID<fa1ac89e-0af3-45cb-80a6-04f92d6b689a@googlegroups.com>
In reply to#79765
On Monday, October 27, 2014 11:05:04 AM UTC+5:30, Chris Angelico wrote:
> On Mon, Oct 27, 2014 at 4:12 PM, Diya Rai <diyaraik@gmail.com> wrote:
> > This is the part of the code which im trying to execute. We are trying to load test a web application through python script, currently checking the login part.
> >
> 
> Does it work when you log in using a web browser? If so, grab a
> browser with debugging facilities (Firefox with Firebug, or Chrome
> with its F12 box, or something), do the login, and have a look at
> exactly what request headers are being sent. Then compare with what
> your script is doing. Once you have the two side by side, you can
> progressively work through it until you figure out which header makes
> the difference - maybe your script isn't sending Host, or maybe you
> need a cookie from a previous request, or maybe it's actually checking
> the Referer and rejecting if it isn't right. Could be all sorts of
> things.
> 
> Good luck! Might be a tedious job, or might be the first thing you try.
> 
> ChrisA

Thanks a lot ChrisA
It works fine while logging in through browser.
Im using firefox, and have checked the headers with firebug.
I tried passing all the headers and it works while passing the cookie header.
My question is whether is it the correct way to try or can i write python script in such a way that it can handle it automatically.
Currently for checking login page, it would be fine.But when we go for testing registration page it become tedious.

I would also like to get your opinion on load testing with python script.

Thanks in advance,
Diya

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web