【问题标题】:How can I format multiple data in a single HTTP POST request in Python?如何在 Python 中的单个 HTTP POST 请求中格式化多个数据?
【发布时间】:2020-11-18 02:53:37
【问题描述】:

我在 Python 的请求库中处理这个 HTTP POST 问题。我无法为 Python 脚本格式化以下 HTTP POST 请求:

curl -X POST https://api.twilio.com/2010-04-01/Accounts/ACauth_code/Messages.json \
  --data-urlencode "To=whatsapp:+1111111111” \
  --data-urlencode "From=whatsapp:+111111111” \
  --data-urlencode "Body=Thanks for contacting me on WhatsApp! Here is a picture of an owl." \
  --data-urlencode "MediaUrl=https://demo.twilio.com/owl.png" \
  -u 'ACauth_code:auth_token

有人可以帮我为 Python requests 库格式化吗?

提前谢谢你!!

【问题讨论】:

    标签: python python-3.x http python-requests


    【解决方案1】:
    import requests
    
    url = "https://api.twilio.com/2010-04-01/Accounts/AC_user/Messages.json"
    params = {
        "To" : "whatsapp:+111111111",
        "From" : "whatsapp:+11111111",
        "Body" : "Thanks for contacting me on WhatsApp! Here is a picture of an owl.",
        "MediaUrl" : "https://demo.twilio.com/owl.png"
        }
    res = requests.post(url, params, auth=('AC_user','password/token'))
    res = res.json()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多