Skip to content

'ResponseObject' object has no attribute 'to_string' #240

@mi6crazyheart

Description

I'm following this (https://www.plivo.com/docs/sms/quickstart/python-flask#api-send-your-first-outbound-sms-mms-message) doc for sending SMS. I'm using the exact source code(shared below), which has been mentioned in the doc. But when executing the "send_sms" endpoint, I get the following error.

File "/Users/skm/Documents/Projects/Python/Flask/sms/send_sms.py", line 17, in outbound_sms
    return Response(response.to_string())
                    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ResponseObject' object has no attribute 'to_string'

Source code -

from flask import Flask, Response
import plivo

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

@app.route('/send_sms/', methods=['GET', 'POST'])
def outbound_sms():
    client = plivo.RestClient('<auth_id>','<auth_token>')
    response = client.messages.create(
    src='<sender_id>',
    dst='<destination_number>',
    text='Hello, from Flask!')
    return Response(response.to_string())

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)

I'm using "Python 3.11.4"

dependencies in "requirements.txt"
blinker==1.6.2
certifi==2023.5.7
charset-normalizer==3.2.0
click==8.1.5
decorator==4.4.2
Flask==2.3.2
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
lxml==4.9.3
MarkupSafe==2.1.3
plivo==4.37.0
PyJWT==2.7.0
requests==2.31.0
six==1.16.0
urllib3==2.0.3
Werkzeug==2.3.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions