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

  • Home
  • SEARCH
  • 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 8927645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:15:56+00:00 2026-06-15T08:15:56+00:00

so that this way all I have to do is type browser = MyBrowser()

  • 0

so that this way all I have to do is type

browser = MyBrowser()
browser.login()

to get my python scripts to log in in the future. Here’s what I have so far:

import mechanize
class MyBrowser(mechanize.Browser, object):
    _username = 'username'
    _password = 'password'

    def __init__(self):
        super(MyBrowser, self).__init__()
        self.set_handle_robots(False)
        self.set_proxies({"http" : "http://proxy.me.com:80"})

    def login(self):
        self.open('http://login.mypage.com/')
        self.select_form(nr=0)
        self['name'] = self._username
        self['pass'] = self._password
        self.submit()

I had made a login function that worked fine using this same methodology. But now, when I call browser.login(), I get this:

self['name'] = self._username
TypeError: 'MyBrowser' object does not support item assignment

Why doesn’t calling select_form behave the same way when it’s part of a method like this?

  • 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-15T08:15:58+00:00Added an answer on June 15, 2026 at 8:15 am

    self is an object of the MyBrowser class.
    What you have done with the self['name'] and self['pass'] is a try to assign values to the self object itself.

    I assume you wanted to declare variables in the class, in order to do that you have to edit your code to:

    self.name = self._username
    self.pass = self._password
    

    Edit:
    Try this one:

    super(MyBrowser, self).name = self._username
    super(MyBrowser, self).password = self._password
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several xml files that are formated this way: <ROOT> <OBJECT> <identity> <id>123</id>
Is there a way to get the exact name of the object that this
I'm trying to use that method this way: public void Method() { ThreadPool.QueueUserWorkItem(() =>
So, i'm trying to parse some xml that looks this way: <image size=extralarge> http://...
Is there a way that this full-text searching query could be translated from MySQL
There is this way, of course: OuterClass.this . But that's very clumsy. Ideally, there'd
When I learned Java, I was told that the arraylist works this way: It
I'm pretty sure there is an easier way to do this that I'm missing
this is a way that i am passing subject line to a methods @subject_text
Found this question that explained a way to communicate between layers. However there is

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.