9

I run Python on windows based environments (2003, win 7, 2008 r2, etc) both 32 and 64-bit flavors. I've recently had to authenticate to various corporate, internally facing web-sites using both NTLM and Kerberos authentication schemes.

I was successful with NTLM authentication using the 'requests' module. Specifically there is some documentation discussing ways for Other Authentication. Installing the 'requests-ntlm' packages worked great!

Unfortunately I cannot seem to get the requests-kerberos package to work. The requirements.txt indicates that the kerberos-1.1.1 package is required, but I am unable to build/install that package.

Here is what happens if I try to import the requests-kerberos library without the kerberos-1.1.1:

>>> import requests
>>> from requests_kerberos import HTTPKerberosAuth
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "requests_kerberos\__init__.py", line 17, in <module>
    from .kerberos_ import HTTPKerberosAuth, REQUIRED, OPTIONAL, DISABLED
  File "requests_kerberos\kerberos_.py", line 1, in <module>
    import kerberos
ImportError: No module named kerberos
>>>

And here is my errors when trying to build the kerberos-1.1.1 package from one of my WIN 7 machines (with python 2.6.5):

>python setup.py install --install-lib "C:\tmp"
running install
running build
running build_ext
building 'kerberos' extension
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox
/MD /W3 /GS- /DNDEBUG -IC:\Python26\ArcGIS10.0\include -IC:\Python26\ArcGIS10.0\
PC /Tcsrc/kerberos.c /Fobuild\temp.win32-2.6\Release\src/kerberos.obj '{' is not
 recognized as an internal or external command, operable program or batch file.
cl : Command line warning D9024 : unrecognized source file type ''{'', object fi
le assumed
cl : Command line warning D9027 : source file ''{'' ignored
cl : Command line warning D9024 : unrecognized source file type 'is', object fil
e assumed
cl : Command line warning D9027 : source file 'is' ignored
cl : Command line warning D9024 : unrecognized source file type 'not', object fi
le assumed
cl : Command line warning D9027 : source file 'not' ignored
cl : Command line warning D9024 : unrecognized source file type 'recognized', ob
ject file assumed
cl : Command line warning D9027 : source file 'recognized' ignored
cl : Command line warning D9024 : unrecognized source file type 'as', object fil
e assumed
cl : Command line warning D9027 : source file 'as' ignored
cl : Command line warning D9024 : unrecognized source file type 'an', object fil
e assumed
cl : Command line warning D9027 : source file 'an' ignored
cl : Command line warning D9024 : unrecognized source file type 'internal', obje
ct file assumed
cl : Command line warning D9027 : source file 'internal' ignored
cl : Command line warning D9024 : unrecognized source file type 'or', object fil
e assumed
cl : Command line warning D9027 : source file 'or' ignored
cl : Command line warning D9024 : unrecognized source file type 'external', obje
ct file assumed
cl : Command line warning D9027 : source file 'external' ignored
cl : Command line warning D9024 : unrecognized source file type 'command,', obje
ct file assumed
cl : Command line warning D9027 : source file 'command,' ignored
cl : Command line warning D9024 : unrecognized source file type 'operable', obje
ct file assumed
cl : Command line warning D9027 : source file 'operable' ignored
cl : Command line warning D9024 : unrecognized source file type 'program', objec
t file assumed
cl : Command line warning D9027 : source file 'program' ignored
cl : Command line warning D9024 : unrecognized source file type 'or', object fil
e assumed
cl : Command line warning D9027 : source file 'or' ignored
cl : Command line warning D9024 : unrecognized source file type 'batch', object
file assumed
cl : Command line warning D9027 : source file 'batch' ignored
cl : Command line warning D9024 : unrecognized source file type 'file.', object
file assumed
cl : Command line warning D9027 : source file 'file.' ignored
kerberos.c
\src\kerberosbasic.h(17) : fatal error C108
3: Cannot open include file: 'gssapi/gssapi.h': No such file or directory
error: command '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.ex
e"' failed with exit status 2 

I also have tried one of my WIN 2008 R2 servers (with python 2.7.2), but get a different error:

>python.exe "setup.py" install --
install-lib "C:\tmp"
running install
running build
running build_ext
building 'kerberos' extension
error: Unable to find vcvarsall.bat

I think this has to do that these are being built from source and need some sort of C or C++ compiler, whereas most other modules I've installed in the past worked great. Any advise is appreciated!

user3233941
  • 93
  • 1
  • 4

2 Answers2

6

I managed to fix this problem.

  1. Install $ pip install kerberos-sspi
  2. Download requests-kerberos ZIP from GitHub
  3. In 'requests-kerberos/kerberos_.py', change the line import kerberos to import kerberos_sspi as kerberos
  4. In 'requirements.txt', delete 'kerberos==1.1.1'
  5. Run $ python setup.py install.

If you want to run test_requests_kerberos.py that is in requests-kerberos/ you need to change import kerberos with import kerberos_sspi as kerberos.

Beside that you need to change all occurrences of:

with patch.multiple('kerberos', ...)

with:

with patch.multiple('kerberos_sspi', ...)

That worked for me.

Rolando Isidoro
  • 4,983
  • 2
  • 31
  • 43
Ivansek
  • 372
  • 5
  • 17
  • Just to follow up on this for anyone else who looks into it, this is obviously a workaround, but the reason this workaround is required is because the kerberos package isn't supported on windows: http://calendarserver.org/ticket/828 "Absent patches, this will not get looked at, as we have no active developers using Windows, so Windows isn't supported. " – JSoet Aug 02 '16 at 00:24
  • I don't believe that is what was meant by "Absent patches, this will not get looked at, as we have no active developers using Windows, so Windows isn't supported. " I'm almost certain it was referring to the fact that the site you found that on was a mac software site, not a kerberos dev site – corporateWhore Aug 17 '16 at 04:13
1

The second problem you can solve with installing Visual Studio 2012 Express and execute this command in command prompt:

> SET VS90COMNTOOLS=%VS110COMNTOOLS%

After executing this command I have a issue with your first problem. Have you solved it?

Ivansek
  • 372
  • 5
  • 17