Vonage / vonage-python-sdk

Vonage Server SDK for Python. API support for Voice, SMS, WhatsApp, Verify (2FA), Video Meetings and more.
https://developer.vonage.com
Apache License 2.0
185 stars 112 forks source link

Messages API (SMS) Authentication Failed. Check you're using a valid authentication method #289

Closed dlewis2017 closed 6 months ago

dlewis2017 commented 7 months ago

Authentication failed. Check you're using a valid authentication method.

Expected Behavior

I expected to be able to initialize Client with application_id and private_key filepath and then send an SMS with messages API.

Current Behavior

I get the error mentioned above : vonage.errors.AuthenticationError: Authentication failed. Check you're using a valid authentication method.

Possible Solution

Seems the local _application_id isn't saving properly so when its checked for here it doesn't exist even though application_id does exist on client.

Steps to Reproduce (for bugs)

Follow tutorial

  1. Load client client = Client(application_id=application_id, private_key=private_key_file)
  2. send message client.messages.send_message({ "channel": "sms", "message_type": "text", "text":body, "from":from_, "to":to })
  3. Error produced

Context

I am trying to follow along with the tutorials and send an SMS via Messages API but getting an authentication error. I've been able to receive messages using messages API webhooks and send messages with SMS API.

Your Environment

maxkahan commented 7 months ago

Hi, the beta version you're using didn't fix this bug, I will probably yank that release. The purpose of it was to expose Video API functionality to developers who wanted early access, but it became out-of-date and has since been superseded by the release of v3.12.0.

Things should work as expected with v3.12.0, please give that one a try!

dlewis2017 commented 7 months ago

Hi @maxkahan , thanks for the reply. So using 3.12.0 doesn't work because I have a version conflict that seems to be resolved in v4.0.0b0. The error I get is:

vonage 3.12.0 requires pydantic==1.*,>=1.10, but you have pydantic 2.5.2 which is incompatible.

We need the latest version of pydantic and other pydantic libraries (like pydantic-settings) require a later version of pydantic (2.*+ I think)

Here are some more errors I got along the way:

when downgrading to Vonage v 3.12.0: ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. pydantic-settings 2.0.0 requires pydantic>=2.0b3, but you have pydantic 1.10.13 which is incompatible.

and when trying to run my application with the above, I get the issue: ModuleNotFoundError: No module named 'pydantic._internal' I imagine because pydantic-settings is looking for that module in pydantic, but older versions of pydantic aren't compatible

So, overall, if possible, I think upgrading pydantic to at least version 2.* should help. Would that be possible?

dlewis2017 commented 7 months ago

I don't have permission to create a branch here but I made a few changes locally that seemed to enable my application to run properly @maxkahan (with a couple warnings). I'm not sure if there are additional changes needed to make sure this function for all users, or if there are tests that need to be updated. But it works for my needs so, the summary is:

I started a Draft pull request here: https://github.com/Vonage/vonage-python-sdk/pull/290

maxkahan commented 6 months ago

Hi David, I started work to update the SDK to use Pydantic v2.x, but that required breaking changes so would have been rolled up into v4 of the SDK. I did some work on this on the old-4.x branch if you want to have a look, but it's incomplete. Priorities changed so I'm currently working on a full rewrite that will use Pydantic v2, as well as other significant changes. That won't be ready for a little while though. Hope this context is helpful!

maxkahan commented 6 months ago

Hi @dlewis2017 we've just released v3.13.0 with v2 support so that should solve this issue!