For anyone reading this thread, if you use Mango v3.3 you can now generate JWT authentication tokens from the users page on the new UI and use these to authenticate instead of logging in from your script.

You do not need to use any CSRF/XSRF protection cookies/headers when using JWT authentication.

Just set the one header on every request -
Authorization: Bearer <token>