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 9247739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:48:30+00:00 2026-06-18T09:48:30+00:00

I am trying to access a site that’s secured with NTLM authentication using python-ntlm

  • 0

I am trying to access a site that’s secured with NTLM authentication using python-ntlm and mechanize but I am getting this error.

File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 203, in open
File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 249, in _mech_open
File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 304, in _set_response
File "build/bdist.macosx-10.6-universal/egg/mechanize/_response.py", line 521, in upgrade_response
File "build/bdist.macosx-10.6-universal/egg/mechanize/_response.py", line 338, in __init__
File "build/bdist.macosx-10.6-universal/egg/mechanize/_response.py", line 353, in _set_fp
AttributeError: HTTPResponse instance has no attribute '__iter__'

I am able to get a proper response when I use the urllib2 library. But for some reason, it fails when I try to access it using mechanize.

This is the code I have.

import urllib2
from ntlm import HTTPNtlmAuthHandler

user = '<myusername>'
password = "<mypass>"
url = "https://somesite.com"

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)
# create the NTLM authentication handler
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)

import mechanize
browser = mechanize.Browser()
handlersToKeep = []

for handler in browser.handlers:
    if not isinstance(handler,
    (mechanize._http.HTTPRobotRulesProcessor)):
        handlersToKeep.append(handler)

browser.handlers = handlersToKeep
browser.add_handler(auth_NTLM)

response = browser.open(url)
print(response.read())

Does anyone has any idea what’s going on? Am I doing something wrongly here?

  • 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-18T09:48:31+00:00Added an answer on June 18, 2026 at 9:48 am

    I patched mechanize to work around this:

    --- _response.py.old    2013-02-06 11:14:33.208385467 +0100
    +++ _response.py    2013-02-06 11:21:41.884081708 +0100
    @@ -350,8 +350,13 @@
                 self.fileno = self.fp.fileno
             else:
                 self.fileno = lambda: None
    -        self.__iter__ = self.fp.__iter__
    -        self.next = self.fp.next
    +
    +        if hasattr(self.fp, "__iter__"):
    +            self.__iter__ = self.fp.__iter__
    +            self.next = self.fp.next
    +        else:
    +            self.__iter__ = lambda self: self
    +            self.next = lambda self: self.fp.readline()
    
         def __repr__(self):
             return '<%s at %s whose fp = %r>' % (
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use FireWatir (1.6.5) to access a site using Basic Authentication and
I have this administration site that is using (Fluent) NHibernate for data access. As
Using NSURLRequest , I am trying to access a web site that has an
I have a very simple sinatra site that I'm trying to access via ajax
I've had some users trying to access a site that is registered as subdomain.example.com
I have a bot that is trying to access my site by entering what
I'm trying to access an internal site project, This is the a part of
I am trying to access a site that is password protected. It is not
I am trying to access a site that is password protected. It is not
I'm experiencing problems when trying to access my sharepoint site using web services (on

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.