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


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

Http post and http get

Started by"n3d!m" <nedimmuminovic@gmail.com>
First post2012-01-25 14:23 -0800
Last post2012-02-06 13:18 -0800
Articles 3 — 2 participants

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


Contents

  Http post and http get "n3d!m" <nedimmuminovic@gmail.com> - 2012-01-25 14:23 -0800
    Re: Http post and http get Jon Clements <joncle@googlemail.com> - 2012-01-25 16:34 -0800
    Re: Http post and http get "n3d!m" <nedimmuminovic@gmail.com> - 2012-02-06 13:18 -0800

#19444 — Http post and http get

From"n3d!m" <nedimmuminovic@gmail.com>
Date2012-01-25 14:23 -0800
SubjectHttp post and http get
Message-ID<26848894.3029.1327530209876.JavaMail.geo-discussion-forums@vbxy22>
I am writing python script which will log into openSIS (Student information system) and get grades. Demo of website is available here: http://demo.os4ed.com/
Here is code which works for that site:

#!/usr/bin/python
import requests
user_login={'USERNAME':'student','PASSWORD':'student'}
r=requests.post("http://demo.os4ed.com/index.php", data=user_login)
r=requests.get("http://demo.os4ed.com/for_export.php?modname=Grades/Transcripts.php&modfunc=save&_openSIS_PDF=true&controller=Y&st_arr[]=1", cookies=r.cookies)
print r.text

My problem is when I try the same thing with my school's openSIS. It returns me error:
<SCRIPT language=javascript>history.back();alert("You must choose at least one student and marking period");</SCRIPT>

Their openSIS is installed on port 8080. Does port 8080 causes problem with my script?

[toc] | [next] | [standalone]


#19454

FromJon Clements <joncle@googlemail.com>
Date2012-01-25 16:34 -0800
Message-ID<c6399cd8-0b10-4b6c-b749-0381baad5bb5@o12g2000vbd.googlegroups.com>
In reply to#19444
On Jan 25, 10:23 pm, "n3d!m" <nedimmumino...@gmail.com> wrote:
> I am writing python script which will log into openSIS (Student information system) and get grades. Demo of website is available here:http://demo.os4ed.com/
> Here is code which works for that site:
>
> #!/usr/bin/python
> import requests
> user_login={'USERNAME':'student','PASSWORD':'student'}
> r=requests.post("http://demo.os4ed.com/index.php", data=user_login)
> r=requests.get("http://demo.os4ed.com/for_export.php?modname=Grades/Transcripts.php&m...[]=1", cookies=r.cookies)
> print r.text
>
> My problem is when I try the same thing with my school's openSIS. It returns me error:
> <SCRIPT language=javascript>history.back();alert("You must choose at least one student and marking period");</SCRIPT>
>
> Their openSIS is installed on port 8080. Does port 8080 causes problem with my script?

Why do you think a port number would make a difference? As long as the
URI you're connecting to, correctly routes to something handling HTTP
- it doesn't matter - and since you're getting "script" tags back, it
implies it does.

I think the response you're getting says it all, although:
1) It should be "javascript" instead of javascript (tho' most of the
time it's omitted)
2) Can't fathom why the history.back() precedes the alert("...")
3) It's normally more polite to go to an error page with an <a
href="...">whatever</a> instead of an alert

For stuff like this, I would use Firefox with Firebug, and manually go
through the process of doing what you're doing, getting where the
posts go etc... etc..., and then try and mimic that.

ie, you find out where submissions take place and what data you
retrieve, it might be that you just require a session cookie and then
can by-pass pretty much all the intermediate pages.

If pages are AJAX generated, it's quite a bit more work, you'll either
need to run some form of web engine, or automate a browser using
selenium. Then you should be able to use lxml.html to parse the DOM
the browser has generated.

hth,

Jon.

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


#19942

From"n3d!m" <nedimmuminovic@gmail.com>
Date2012-02-06 13:18 -0800
Message-ID<31716695.3432.1328563095624.JavaMail.geo-discussion-forums@vbek1>
In reply to#19444
Cookies work because I am able to login on website and GET other pages.

[toc] | [prev] | [standalone]


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


csiph-web