I apologise if the titles too vague.
In Maya (PyMel) im calling a function below to draw a login screen
def ms_ui(self):
logged_in = False
if not logged_in:
login_col = pm.rowColumnLayout(numberOfColumns=3)
usr = pm.textField(text="username")
usr_val = pm.textField(usr, text=True, q=True)
pwd = pm.textField(text="Password")
pwd_val = pm.textField(pwd, text=True, q=True)
pm.button(label="Log in!", c=lambda x: ms.ms_login(usr_val, pwd_val))
Clicking the login button then calls ms.ms_login and passes the values of the username and password to the function
def ms_login(user, passwd):
import urllib2, base64, json
username = user
password = passwd
param = {"secret": "thesecretgoeshere"}
url = "https://someurl/api/token"
base64string = base64.b64encode('%s:%s' % (username, password))
req = urllib2.Request(url,
headers = {
"Authorization": "Basic %s" % base64string,
"Content-Type": "application/json"
})
f = urllib2.urlopen(req, json.dumps(param))
data = f.read()
print data
However I'm getting the following error
Error: HTTP Error 400: Bad Request
Traceback (most recent call last):
File "C:\Program Files\Autodesk\Maya2017\Python\lib\site-packages\pymel\internal\factories.py", line 785, in callback
res = origCallback(*newargs)
File "D:/Documents/maya/2017/scripts\MMB\MMB.py", line 223, in <lambda>
pm.button(label="Log in!", c=lambda x: ms.ms_login(usr_val, pwd_val))
File "D:/Documents/maya/2017/scripts\MMB\ms.py", line 13, in ms_login
f = urllib2.urlopen(req, json.dumps(param))
File "C:\Program Files\Autodesk\Maya2017\bin\python27.zip\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Program Files\Autodesk\Maya2017\bin\python27.zip\urllib2.py", line 437, in open
response = meth(req, response)
File "C:\Program Files\Autodesk\Maya2017\bin\python27.zip\urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Program Files\Autodesk\Maya2017\bin\python27.zip\urllib2.py", line 475, in error
return self._call_chain(*args)
File "C:\Program Files\Autodesk\Maya2017\bin\python27.zip\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Program Files\Autodesk\Maya2017\bin\python27.zip\urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 400: Bad Request #
Now, I know what a 400 bad request is, but I don't understand why i'm getting one. Executing that function on its own within a maya console gives me the results I want, it only seems to be when calling the function with lambda or partial.
Couldn't really find a solution when searching (And I apologise, never really used urllib before)
Any advice would be appreciated, thanks!