joeyagreco / pythontextnow

Send SMS messages from Python! A Python wrapper for TextNow.
https://pypi.org/project/pythontextnow/
MIT License
19 stars 3 forks source link

I keep getting HTTPError: 403 Client Error: Forbidden for url: https://www.textnow.com/api/users/my_username/messages #35

Open xoy74 opened 4 weeks ago

xoy74 commented 4 weeks ago

I can't get a simple script to send a test message. I keep getting an error 403 The code looks like this: from pythontextnow import Client USERNAME = "myuser.name" SID_COOKIE = see below Client.set_client_config(username=USERNAME, sid_cookie=SID_COOKIE) from pythontextnow import ConversationService PHONE_NUMBER = "+14165551234" conversation_service = ConversationService(conversation_phone_numbers=[PHONE_NUMBER]) conversation_service.send_message(message="Hello World!") The error I get:

Traceback (most recent call last): File "/home/liviu/textnow/victor/test.py", line 13, in conversation_service.send_message(message="Hello World!") File "/usr/local/lib/python3.11/dist-packages/pythontextnow/service/ConversationService.py", line 89, in send_message self.text_now_api.send_message(message=message, send_to=self.conversation_number) File "/usr/local/lib/python3.11/dist-packages/pythontextnow/decorator/cooldown.py", line 29, in wrapFunction return function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pythontextnow/api/TextNowAPI.py", line 60, in send_message response.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://www.textnow.com/api/users/myuser.name/messages

Clearly I am missing something in the authentication but I have no idea what. The cookie looks like this (I changed a few characters from the real one) connect.sid=s%3Ah1zL9MFKwr3YU2EhgRexzB8zW7EZnPYI.xeFi4FWhEgBLPWUcfhkOgG7v2wvDyCzYEU3%2FOoJLS5E Does it mean my SID_COOKIE = "s%3Ah1zL9MFKwr3YU2EhgRexzB8zW7EZnPYI.xeFi4FWhEgBLPWUcfhkOgG7v2wvDyCzYEU3%2FOoJLS5E" ? I tried also to replace %3A and %2F so the string becomes SID_COOKIE = "s:h1zL9MFKwr3YU2EhgRexzB8zW7EZnPYI.xeFi4FWhEgBLPWUcfhkOgG7v2wvDyCzYEU3/OoJLS5E" but neither one works. Also, my username has a period, does that character need to be escaped in some way ? Thanks for any feedback

Anti-Apple4life commented 2 weeks ago

it might be something with the user agent, sometimes it works, and sometimes i get this error

xoy74 commented 2 weeks ago

Thanks. What is the correct user agent and how can one specify it ?

joeyagreco commented 1 week ago

Try again with version 1.1.0

pip install --upgrade pythontextnow

xoy74 commented 5 days ago

Thank you so much for the update. It does work now. There was another issue, which I just realized. TextNow kept telling me to disconnect the VPN when I was trying to use it from the browser. Obviously I had no VPN and couldn't figure out how to get rid of the error. When I released the IP address from my ISP and got a new IP, the error went away.

YiYang02 commented 4 days ago

Having the same issue right now with the same identical code as above. My username and SID is correct as I'm able to use other methods such as get_messages() and print out messages, but when it comes to send_message(), I am getting the 403 Client Error.

I have also tried "pip install --upgrade pythontextnow"

xoy74 commented 4 days ago

Are you able to send messages from a browser from the same IP address ? One of my issues was that I was getting an error "turn off VPN" when sending from the browser, at the same IP address.

YiYang02 commented 3 days ago

What do you mean by sending messages from the same IP address? I don't have VPN installed. I am not getting a "turn off VPN" error - how did that come about? Was it through the IDE?

I also tried to release my ip address via sudo ipconfig set en0 DHCP, my ip address became undetected and I just got back my same ip address as before

Edit: was able to get the vpn error popup by going on safari. i was initially on chrome

xoy74 commented 3 days ago

Then I am guessing your issue isn't the same as mine. I was working with 2 PCs. One was a Linux machine where I was trying to run the pythontextnow script and one was a Windows box where I logged in from a web browser to collect the cookie, etc. Both machines were running behind the same firewall/public IP, with no VPN (but somehow TextNow had my IP address flagged as being some VPN provider). The Windows one was giving me the VPN error while the Linux one was just throwing the 403 error. When I restarted the internet connection to get another IP address, both PCs started working.