Getting username blank error with API Authorization

Issue
Trying to connect to the REST API using POST /api/session to authorize.

Getting error:
{"errors":{"username":"value must be a non-blank string."}}

Steps to Reproduce

  1. Run jar file
  2. Sign into Metabase
  3. Open Python
  4. Execute the following:

url = "https://localhost:3000/api/session"

payload= {}
headers= {
  'username': '_email@email.com_',
  'password': '_password_'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

I Have Also Tried

  • Used Postman to send the call. Same error
  • Switching Headers and Payload in Python request. Results in SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_record', 'wrong version number')])
  • Used curl to send the call (curl -X POST -d "Content-Type: application/json" -H '{"username": "email@email.com", "password": "password"}' http://localhost:3000/api/session) . Same error
  • Switched -d and -H in curl: curl -X POST -H "Content-Type: application/json" -d '{"username": "email@email.com", "password": "password"}' http://localhost:3000/api/session. Same error
  • Removed Content-Type header: curl -X POST -d '{"username": "email@email.com", "password": "password"}' http://localhost:3000/api/session. Same error.

Metabase Version

  • Metabase 0.35.3
  • Using jar file

Finally got it to work in Postman.

I added the following to the body:
{“username”:“email@gmail.com”,
“password”:“password”}

BTW, there are already three Python wrappers for Metabase API (here, here and here).

1 Like