Stranger6667 / postmarker

Python client library for Postmark API
https://postmarker.readthedocs.io/en/stable/
MIT License
134 stars 29 forks source link

"You have to provide token use Postmark API", with env or variables. #199

Closed mtthidoteu closed 2 years ago

mtthidoteu commented 2 years ago

Hi! So I'm trying to send a simple mail for testing purposes, however It is not letting me using any ENV variables or any sort of variable for that matter:

def sendmail():
  postmark = PostmarkClient(server_token=os.getenv('POSTMARK_API_KEY'))
  postmark.emails.send(
    From='something@examples.com',
    To='something@examples.com',
    Subject='Postmark',
    HtmlBody='Hi',
  )

I am getting the error:

AssertionError: You have to provide token to use Postmark API

If I put it between straight away between ''s it works however. I can also not declare it before such as:

server_token=os.getenv('POSTMARK_API_KEY')
def sendmail():
  postmark = PostmarkClient(server_token=server_token)
  postmark.emails.send(
    From='something@examples.com',
    To='something@examples.com',
    Subject='Postmark',
    HtmlBody='Hi',
  )

As this returns the same error. Is this the intended behaviour? What could I do as an alternative? Cheers

Stranger6667 commented 2 years ago

Hi!

It doesn't seem related to the library itself as it doesn't grab any env vars by itself - the issue is on your side. The only thing the library does is check if the caller provided None as the server token - how the caller gets the token, it's on the caller.