pythontextnow icon indicating copy to clipboard operation
pythontextnow copied to clipboard

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

Open xoy74 opened this issue 1 year ago • 17 comments

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

xoy74 avatar Aug 15 '24 02:08 xoy74

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

AntiApple4life avatar Aug 24 '24 23:08 AntiApple4life

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

xoy74 avatar Aug 25 '24 23:08 xoy74

Try again with version 1.1.0

pip install --upgrade pythontextnow

joeyagreco avatar Sep 06 '24 03:09 joeyagreco

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.

xoy74 avatar Sep 07 '24 20:09 xoy74

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"

YiYang02 avatar Sep 09 '24 03:09 YiYang02

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.

xoy74 avatar Sep 09 '24 11:09 xoy74

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

YiYang02 avatar Sep 10 '24 03:09 YiYang02

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.

xoy74 avatar Sep 10 '24 14:09 xoy74

I have same error. I have updated version to 1.1.0 with pip install --upgrade pythontextnow I have also updated the SID_COOKIE.

llaalways avatar Dec 02 '24 20:12 llaalways

@joeyagreco Using pythontextnow 1.1.0 for a while, recently have not been able to connect and getting error: "File "/opt/PythonTextNow/Keep_TextNow_Alive.py", line 27, in conversation_service.send_message(message=QUOTE) File "/opt/PythonTextNow/venv/lib/python3.10/site-packages/pythontextnow/service/ConversationService.py", line 107, in send_message self.__text_now_api.send_message( File "/opt/PythonTextNow/venv/lib/python3.10/site-packages/pythontextnow/decorator/cooldown.py", line 33, in wrapFunction return function(*args, **kwargs) File "/opt/PythonTextNow/venv/lib/python3.10/site-packages/pythontextnow/api/TextNowAPI.py", line 63, in send_message response.raise_for_status() File "/opt/PythonTextNow/venv/lib/python3.10/site-packages/requests/models.py", line 1024, 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/XXX/messages

@joeyagreco PS: changed to a new SID Cookie but get same connection error. Do not know if this would cause the error but the user agents seems to have changed. Where does this get specified?

ClearlyDazed avatar Feb 03 '25 22:02 ClearlyDazed

I too am getting this error now on Debian 12+Python3.11.

Traceback (most recent call last): File "/home/textnow/ptn.py", line 17, in conversation_service.send_message(message="Hello World!") File "/usr/local/lib/python3.11/dist-packages/pythontextnow/service/ConversationService.py", line 107, in send_message self.__text_now_api.send_message( File "/usr/local/lib/python3.11/dist-packages/pythontextnow/decorator/cooldown.py", line 33, in wrapFunction return function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pythontextnow/api/TextNowAPI.py", line 63, in send_message response.raise_for_status() File "/usr/local/lib/python3.11/dist-packages/requests/models.py", line 943, 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/USERNAME/messages

This was also on a fresh SID cookie. A different Python TextNow API project that had been working stopped working sometime between January 31st and February 7th of 2025. Is it possible that TextNow has changed their API? Many thanks to @joeyagreco for this project and any help on this would be appreciated.

radar27 avatar Feb 14 '25 15:02 radar27

Same. 403 error. I'm guessing textnow made some changes?

dellmas avatar Feb 17 '25 14:02 dellmas

I am also getting 403 error, even with updated cookie. I was using this script with 2 accounts, to keep the numbers from expiring, and one account already got blocked. It feels that somehow TextNow are now able to detect when someone uses this script.

xoy74 avatar Mar 05 '25 22:03 xoy74

I am not actively maintaining this, as I currently have no incentive to do so and have other obligations.

As long as TextNow works in a browser, fixing issues like this should be relatively trivial.

Pull requests are welcome.

joeyagreco avatar Mar 06 '25 01:03 joeyagreco

got 403 errors in the past few days, today it's magically working again.

plutoids1 avatar Mar 12 '25 15:03 plutoids1

Took a long look at resolving the 403 error, with no success. The conclusion I come to is that TextNow is now using Cloudflare which is blocking python requests. Beyond my ability on how to get around this... @joeyagreco

ClearlyDazed avatar Mar 15 '25 20:03 ClearlyDazed

Took a long look at resolving the 403 error, with no success. The conclusion I come to is that TextNow is now using Cloudflare which is blocking python requests. Beyond my ability on how to get around this... @joeyagreco

@ClearlyDazed et al. Please refer to Issue 39 for a solution.

garycnew avatar Jul 11 '25 07:07 garycnew