Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:47:03+00:00 2026-06-10T09:47:03+00:00

I have a bash script, that logs in with a cookie and saves a

  • 0

I have a bash script, that logs in with a cookie and saves a text file from a URL. I need to achieve the same thing in Python with Mechanize, but I can’t get it working. It’s only two lines of bash and it’s driving me mad. I’ve looked at the Mechanize docs, but can’t find out how to do it.

#!/bin/sh
base_url=https://myapp.url.com
sign_on_request="aK8Rj_mrVk3J-PDf9x6...LONG KEY...4ZPMd0w"
# Login
wget -q --keep-session-cookies --save-cookies savedcookie.txt --post-data="sign_on_request=$sign_on_request" -O - $base_url/login > /dev/null 2>&1
# Save CSV
wget -q --load-cookies savedcookie.txt -O output.txt $base_url/data

Here’s what I tried:

import mechanize
import cookielib

# Browser
br = mechanize.Browser()

# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Login
req = mechanize.Request("https://myapp.url.com/login", "sign_on_request=aK8Rj_mrVk3J-PDf9x6...LONG KEY...4ZPMd0w")
cj.add_cookie_header(req)
res = mechanize.urlopen(req)

# Download
f = br.retrieve('https://myapp.url.com/data')[0]
print f
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:47:05+00:00Added an answer on June 10, 2026 at 9:47 am

    Have you tried res = br.open("https://myapp.url.com/login", data=...) instead of mechanize.Request? Seems you would need to use the browser you created to do the login if you expect it to be able to do the retrieval.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bash script that sources contents from another file. The contents of
I have a bash script that I need to write my password to run
I would like to have a shell script that copies some logs from a
I have a bash script that is invoked from a cron job which has
I have a sh/bash script that needs to call a batch file with parameters
Greetings, I have a bash script that parses ZIP files we receive from a
I have a bash script that creates a Subversion patch file for the current
I have written a small bash script which clears the logs (say that script
I have a bash script that has set -x in it. Is it possible
I have a bash script that does ssh to a remote machine and executes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.