0

I'm trying to convert these sequence of CURL commands into python script. Can someone assist me on this please? There should be function/method for command 3 and 4 below which will accept the parameter as "data" to pass to command 3 below and note to process as query argument in command 4 below(eg. of node in command 4 below: cid=29-0&pid=12&gid=29-0&type=1")

curl --cookie-jar /mydir/cookies.tmp -o dev/null "http://xyz:8080/main/main.faces"

curl --cookie /mydir/cookies.tmp  --location --cookie-jar /mydir/cookies.tmp --data "[email protected]&j_password=test" -o /dev/null "http://xyz.com:8080/main/j_sec_check"

curl --cookie /mydir/cookies.tmp --data "cmd=u&rid=5&cid=29-0&pid=12&gid=29-0&type=1&blablblablablablablablblablablablablablblablablablablablblablablabla" "http://xyz.com:8080/main/rest/testrestXML"

curl --cookie /mydir/cookies.tmp "http://xyz.com:8080/main/rest/process?cid=29-0&pid=12&gid=29-0&type=1"
1
  • I usually do, but if I have missed any then I'm sorry. I will make sure moving forward Commented Jan 4, 2011 at 20:53

1 Answer 1

3

Well, without doing it all for you, start with urllib2. The relevant function is urllib2.urlopen("http://www.example.com"). If you pass a second parameter, it is treated as the data in a POST request. To do a GET request, just add url encoded parameters to the URL. urllib (without the 2) has a urlencode function if you need it.

If you need to use cookies, use cookielib. The examples for it show you how.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Thomas for your tip. It helped to increase my knowledge base. What I did was constructed cmd and used os.system(cmd) to achieve that task and wrapped in python function.
@doneright: You're welcome. Calling system commands isn't ideal (not very portable, etc.), but if it only needs to work on one computer, fair enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.