There is some issues but you can fix with updating
Now you need the EXACT user agent same as your logged in computer to work
@LongpanZhou
Will you share an example of how to configure the user-agent within a sample pythontextnow send message script?
Thank you.
After reviewing the pythontextnow code, I believe I understand where @LongpanZhou made the user-agent header change in pythontextnow/api/Client.py.
So... I downloaded the raw pythontextnow/api/Client.py and pythontextnow/util/general.py source code. Made the change to remove the get_random_user_agent function and replace it with a user configurable user_agent variable.
$ diff -u pythontextnow/api/Client.py.old pythontextnow/api/Client.py
--- pythontextnow/api/Client.py.old
+++ pythontextnow/api/Client.py
@@ -5,9 +5,7 @@
from dataclasses import dataclass
from typing import Optional
-from pythontextnow.util.general import get_random_user_agent
-
@dataclass(kw_only=True)
class ClientConfig:
"""
@@ -28,14 +26,14 @@
client_config: Optional[ClientConfig] = None
@classmethod
- def set_client_config(cls, *, username: str, sid_cookie: str) -> None:
+ def set_client_config(cls, *, username: str, sid_cookie: str, user_agent: str) -> None:
# use the same user agent for the same username + sid cookie combo
# we do this by creating a hash of them and then using it as a seed
hash: int = int(
hashlib.sha256(f"{username}+{sid_cookie}".encode()).hexdigest(), 16
)
headers = {
- "user-agent": get_random_user_agent(hash),
+ "user-agent": user_agent,
"Cookie": f"connect.sid={sid_cookie};",
}
$ diff -u pythontextnow/util/general.py.old pythontextnow/util/general.py
--- pythontextnow/util/general.py.old
+++ pythontextnow/util/general.py
@@ -1,23 +1,5 @@
-import random
import re
-from typing import Optional
-from random_user_agent.params import OperatingSystem, SoftwareName
-from random_user_agent.user_agent import UserAgent
-
def replace_newlines(text: str):
- return re.sub(r"(?<!\\)\n", r"\\n", text)
-
-
-def get_random_user_agent(seed: Optional[int] = None) -> str:
- software_names = [SoftwareName.CHROME.value]
- operating_systems = [OperatingSystem.WINDOWS.value, OperatingSystem.LINUX.value]
- user_agent_rotator = UserAgent(
- software_names=software_names, operating_systems=operating_systems, limit=100
- )
-
- if seed is not None:
- random.seed(seed)
-
- return random.choice(user_agent_rotator.get_user_agents())["user_agent"]
+ return re.sub(r'(?<!\\)\n', r'\\n', text)
Then... I compiled the new source $ python -m compileall Client.py Client.py, $ python -m compileall general.py general.py and replaced the old versions with the new ones $ mv __pycache__/Client.cpython-311.pyc ./Client.pyc and $ mv __pycache__/general.cpython-311.pyc ./general.pyc
# cat ./sendtextnow
#!/usr/bin/env python3
from pythontextnow import Client
USERNAME = "garycnew1670"
SID_COOKIE = "s%3Ay2QzHRFfqtfeC8qEfZE9GmVNYDx3HYNu.TagWLD3Jsv65qu4AvFCPHtZy%2Bjfgv1iznpkp4Fjy8eg"
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
Client.set_client_config(username=USERNAME, sid_cookie=SID_COOKIE, user_agent=USER_AGENT)
from pythontextnow import ConversationService
#PHONE_NUMBER_1 = "{some_phone_number}"
#PHONE_NUMBER_2 = "{some_other_phone_number}"
#conversation_service = ConversationService(conversation_phone_numbers=[PHONE_NUMBER_1, PHONE_NUMBER_2])
PHONE_NUMBER = "+18015551234"
conversation_service = ConversationService(conversation_phone_numbers=[PHONE_NUMBER])
conversation_service.send_message(message="Test 1")
@joeyagreco I believe the long-term solution is the user configurable pythontextnow USER_AGENT variable that can be configured with the USERNAME and SID_COOKIE variables to allow custom configuration of the EXACT user-agent used by the already authenticated browser. Will you accept a Pull Request? Thanks!
P.S. I believe you'll find more and more organizations may be interested in using your pythontextnow module as more Telecom companies discontinue their email2sms services. I have gone so far as to create a Makefile that packages python3-textnow for the OpenWRT and Entware distro's. Thanks, again!
@joeyagreco anyway to open a pull request for this since only collaborators can make a pull request for this repo. Just tried out the fix and it works fine for me.
@Rocketboy235 Since it's a public repo, anyone should be able to open a PR.
@Rocketboy235 Since it's a public repo, anyone should be able to open a PR.
Ah okay, I guess maybe it's the other repo that I was trying to do the pull request into this one that was responsible for saying I need collaborator role. I guess I'll see if they can open a pull request or I can fork and copy the changes over and open a pull request too
@joeyagreco I attempted to initiate a PR; when, I originally provided the patches in July. However, it stated that I didn't have permission and is the reason why I resorted to updating this issue with the code. I believe my original PR has expired, now.
Begging someone to keep this alive somehow, i can verify the fix is still working as of 11/29/2025 just a next js app i made with cursor ai in literally less than a minute and it is sending text messages tho its not receivng old messages to display in the user interface
I realized that it's simpler to create a shell script and send a POST Request via wget or curl (supplying the variables and cookies from the pre-authenticated, dedicated texnow browser session). Ensure you URLEncode the phone_number and message.
#!/bin/sh
first_name="John"
last_name="Doe"
user="john1973"
phone_number="%2B12125551234"
message="START_OF_LINE%0D%0AHello%0D%0AEND_OF_LINE"
url="https://www.textnow.com/api/users/$user/messages"
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0"
wget --post-data="from_name=${first_name}+${last_name}&has_video=false&contact_value=${phone_number}&contact_type=2&message=${message}&read=1&message_direction=2&message_type=1&new=true" --tries=1 -o - -O - --no-check-certificate --save-cookies wget-cookies.txt --keep-session-cookies --load-cookies wget-cookies.txt -U "$user_agent" $url
Happy Holidays
Thanks, that worked. Here's my script, you need to replace:
"+1888123456" with your recipient's number "my user id" with your user id and lastly, download your cookies file and save it to $HOME/cookies.txt.
I use this firefox extension to download the cookies file. https://github.com/hrdl-github/cookies-txt
#!/bin/sh
first_name="John" last_name="Doe" phone_number="+1888123456"
user="my user id" url="https://www.textnow.com/api/users/$user/messages" message="hello from $user" user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0"
wget --post-data="from_name=${first_name}+${last_name}&has_video=false&contact_value=${phone_number}&contact_type=2&message=${message}&read=1&message_direction=2&message_type=1&new=true" --tries=1 -o - -O - --no-check-certificate --save-cookies $HOME/cookies.txt --keep-session-cookies --load-cookies $HOME/cookies.txt -U "$user_agent" $url
People are still on this thread?
@garycnew 🐐
@LongpanZhou I am here because i needed to make a free way to send sms text notification from personal web application and developing a Home assistant integration to do the same I came across two 3rdy party apis (PythonTextNow & PyTextNow) i have to say tho the creators of both arent keeping up with the code users in the issue sections are finding ways to keep it alive. And the i highly recommend people try out PyTextNow which give you full functionality of text now as if you were on their website because it makes request the same exact way.
Here what i made with PyTextNow Onload it loads all conversations attached to you current text now number (dont need recipients number to load convos) Can Send sms, mms, and voice message. I also added a new feature to generate ai voice messages using googles geminis free api and send it as a voice message
The below images are what i made with PyTextNow not with this api PythonTexnow
Things i can do in the future is implementing webhooks so the app functions as just an interface for pytextnow who can manage then manage webhook calls to and from your other apps instead of implementing it from scratch in your current and future projects. Regardless i do love that both developers took the time out to explore the api!
You can check out both projects PyTextNow PythonTextNow (no longer works, literally worked for 24 hours)
@zodyking Excellent work with your new TextNow api! However, you might consider giving it a different name, as you've acknowledged that there is already a project (PyTextNow), by the same name, written is python. Moreover, your api appears to use Node.js and is written in Javascript. How about calling your api something like TextNow.js, so not to confuse it with the python api of the same name? Keep up the great work!