【问题标题】:Python OPTIONS/GET requestsPython 选项/获取请求
【发布时间】:2016-12-14 19:16:11
【问题描述】:

过去几个小时我一直坚持这一点。想不通这个。我在邮递员上对此进行了测试,效果很好。但在 python 中,我不断收到 405 个请求。

原始 API 请求

OPTIONS /sessions HTTP/1.1
Host: elb.deposit.shopifycs.com
Access-Control-Request-Method: POST
Origin: https://checkout.shopifycs.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Access-Control-Request-Headers: content-type
Accept: */*
Referer:
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache

url = 'https://elb.deposit.shopifycs.com/'
resp = session.options(url, headers = Headers)
print resp.status_code, ' status'

【问题讨论】:

  • 返回 HTTP 错误 405 方法的服务器 ID 不允许您的代码针对 httpbin.org/get。允许登录您的服务器
  • 对不起。我很困惑。网站阻止了我的获取/选项请求?这不是我的服务器。
  • 抱歉,URL elb.deposit.shopifycs.com/sessions 与您在邮递员中使用的一样
  • 是的,我用邮递员试过了,效果很好。知道为什么我的代码不起作用吗?
  • 您在邮递员中使用不同的 URL /sessions

标签: python httprequest python-requests http-status-codes


【解决方案1】:

为了记录,答案是使用正确的 URL。

url = 'https://elb.deposit.shopifycs.com/sessions'

(我希望发布答案可以防止其他人花太多时间看它)

【讨论】:

    猜你喜欢
    • 2015-04-24
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 2015-03-04
    相关资源
    最近更新 更多