Python Text Messaging Bot verwendet Flask, Twilio, Ngrok und sendet doppelte Textnachrichten [geschlossen]Python

Python-Programme
Anonymous
 Python Text Messaging Bot verwendet Flask, Twilio, Ngrok und sendet doppelte Textnachrichten [geschlossen]

Post by Anonymous »

Wenn ich diesen Python-Code verwende, um nur „Text“ in einer Textnachricht zu senden, funktioniert alles ordnungsgemäß.

Der Python Bot.py kann mit Ngrok Textnachrichten von meinem Computer senden. Der Python Bot.py kann die Textnachricht auch über einen virtuellen Server auf Pythonanywhere.com versenden

Code: Select all

    #Send text message only

#create twilio client using the account_sid, auth_token

client = Client(account_sid, auth_token)

message = client.messages.create(
to= from_number, # to phone number
from_=to_number,# from phone number
body= return_body  # return_body is the text to send
)
return str(message)
Wenn ich jedoch diesen Code verwende, um Text und eine Bild-URL in einer Textnachricht zu senden, wird die Textnachricht an die richtige Telefonnummer gesendet. Die Bilder werden jedoch an dieselbe Telefonnummer gesendet, jedoch ohne die Landesvorwahl in der Telefonnummer. Der Mobilfunkanbieter erkennt die Nachrichten als zwei separate Textnachrichten und sendet den Text an +1(886) 555-5555 und die Bilder an 8865555555.

Code: Select all

    #Sending a text message and image URLs

#create twilio client using the account_sid, auth_token
client = Client(account_sid, auth_token)

message = client.messages.create(
to= from_number, #to phone number
from_=to_number, # from phone number
body= return_body, # return_body is the text to send
media_url=['https://www.example.com/images/logo.jpg', 'https://www.example.com/bot/Help-Desk.jpg'] # send the image Url's
)
return str(message)
Irgendwelche Ideen zur Lösung dieses Problems, bei dem die Bild-URL an eine Telefonnummer ohne Landesvorwahl gesendet wird?

Code: Select all

No errors on the PythonAnywhere server, just an access log
[15/Jan/2026:17:45:30 +0000] "POST /bot HTTP/1.1" 200 120 "-" "TwilioProxy/1.1" "3.91.250.130" response-time=0.658

Twilio server logs
I get this Error whether I send just a text message, or a text message and media_url

Twilio Error - 12200
## Warning - 12200 ### Schema validation warning The provided XML does not conform to the Twilio Markup XML schema. Please refer to the specific error and correct the problem.
WARN
Msg
Open quote is expected for attribute "account_sid" associated with an element type "Twilio.Api.V2010.MessageInstance".

on my computer: for debugging, however there's nothing in this log to indicate Twilio is sending the text and media_url to a phone number without a country code.
2026-01-15 07:04:47,234 WARNING:werkzeug: * Debugger is active!
2026-01-15 07:04:47,236 INFO:werkzeug: * Debugger PIN: 367-270-892
2026-01-15 07:05:08,148 INFO:twilio.http_client:-- BEGIN Twilio API Request --
2026-01-15 07:05:08,148 INFO:twilio.http_client:POST Request: https://api.twilio.com/2010-04-01/Accounts/ACfcd9ffcc0a2e95040bec14117500f2bf/Messages.json
2026-01-15 07:05:08,148 INFO:twilio.http_client:Headers:
2026-01-15 07:05:08,148 INFO:twilio.http_client:Content-Type : application/x-www-form-urlencoded
2026-01-15 07:05:08,148 INFO:twilio.http_client:Accept : application/json
2026-01-15 07:05:08,149 INFO:twilio.http_client:User-Agent : twilio-python/9.9.0 (Windows AMD64) Python/3.14.2
2026-01-15 07:05:08,149 INFO:twilio.http_client:X-Twilio-Client : python-9.9.0
2026-01-15 07:05:08,149 INFO:twilio.http_client:Accept-Charset : utf-8
2026-01-15 07:05:08,149 INFO:twilio.http_client:-- END Twilio API Request --
2026-01-15 07:05:08,150 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.twilio.com:443
2026-01-15 07:05:08,676 DEBUG:urllib3.connectionpool:https://api.twilio.com:443 "POST /2010-04-01/Accounts/ACfcd9ffcc0a2e95040bec14117500f2bf/Messages.json HTTP/1.1" 201 806
2026-01-15 07:05:08,677 INFO:twilio.http_client:Response Status Code: 201
2026-01-15 07:05:08,677 INFO:twilio.http_client:Response Headers: {'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '806', 'Connection': 'keep-alive', 'Date':   'Thu, 15 Jan 2026 15:05:09 GMT', 'Twilio-Concurrent-Requests': '1', 'Twilio-Request-Id': 'RQ347c91aa845fabecd7b6db', 'Twilio-Request-Duration': '0.124', 'X-Home-Region': 'us1',    'X-API-Domain': 'api.twilio.com', 'Strict-Transport-Security': 'max-age=31536000', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 230a4cabf962361d7a66119623a370ee.cloudfront.net   (CloudFront)', 'X-Amz-Cf-Pop': 'SFO53-P10', 'X-Amz-Cf-Id': 'bCzU4lDCjk3a4tSYm9Q8r7Wz7==', 'X-Powered-By': 'AT-5000', 'X-Shenanigans': 'none', 'Vary': 'Origin'}
2026-01-15 07:05:08,677 INFO:root:Message SID: SM347c91aa845fabecd7b
2026-01-15 07:05:08,677 INFO:werkzeug:127.0.0.1 - - [15/Jan/2026 07:05:08] "POST /bot HTTP/1.1" 200 -

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post