3

Trying to do a REST POST with requests in python. The below code works if I specify a password without any special characters, but as soon as I specify a user which have for example "!" in the password, it will no longer work. (I get a 400 response back from the server.)

import requests


user = 'username'
password = 'Passwd!'
params = {'name': 'user', 'mail': 'address'}
requests.post("https://webserver.com/regName", auth=HttpNtlmAuth('domain\\%s' % (user),'%s' % (password), params=params)

I have tried to encode the password in various ways, but no luck. Anyone have an idea what I can do to solve this?

Martin Gergov
  • 1,556
  • 4
  • 20
  • 29
m.wahlstam
  • 53
  • 4
  • Can you sniff and see what's going on? Perhaps try using %21 instead of the exclamation mark – Ofir Israel Sep 06 '13 at 13:31
  • 1
    I never used NTLM, but requests-ntlm states that password can be hashed (":password - Password or hash in "ABCDABCDABCDABCD:ABCDABCDABCDABCD" format") in https://github.com/requests/requests-ntlm/blob/master/requests_ntlm/requests_ntlm.py. Still don't know what hashing function they use, but it might be worth trying. – matiasg Sep 06 '13 at 13:53
  • You should be using requests-ntlm to handle the NTLM authentication. It was designed with requests in mind and I doubt HttpNtlmAuth does what we (the maintainers of requests) intend for an Auth class to do. – Ian Stapleton Cordasco Sep 07 '13 at 01:09
  • @sigmavirus24 You mean this: https://github.com/requests/requests-ntlm ? That's what I'm using... – m.wahlstam Sep 09 '13 at 05:49
  • @sigmavirus24 You know how I can hash the password in a correct way that requests-ntlm will understand? If that can help me to solve my problem... – m.wahlstam Sep 09 '13 at 13:40
  • What happens if you use an escape character before the special character (e.g. "Passwd\!")? – Ben Sep 29 '13 at 04:32

0 Answers0