方法不允许,flask,python

huangapple go评论68阅读模式
英文:

Method not allowed, flask, python

问题

已在Docker中安装了FlareSolverr。

cURL正常工作并返回正确的响应。

curl -L -X POST 'http://localhost:8191/v1' -H 'Content-Type: application/json' --data-raw '{
  "cmd": "request.get",
  "url":"http://google.com",
  "maxTimeout": 60000
}'

但是,当从Python + Flask中使用时,我收到一个错误 - 405方法不允许。

def get_parsed_page(url, delay=0.5):
    data = {
        "cmd": "request.get",
        "url": url,
        "maxTimeout": 60000
    }
    headers = {"Content-Type": "application/json"}
    time.sleep(delay)
    print(requests.get("***:8191/v1", headers=headers, data=data))
    return BeautifulSoup(requests.get("***:8191/v1", headers=headers, data=data).text, 'lxml')

请注意,您需要将***替换为您实际的地址。

英文:

Installed FlareSolverr in docker.

cURL work correctly and return the correct response.

curl -L -X POST 'http://localhost:8191/v1' -H 'Content-Type: application/json' --data-raw '{
  "cmd": "request.get",
  "url":"http://google.com",
  "maxTimeout": 60000
}'

but when using from python + flask I get an error - 405 Method is not allowed

def get_parsed_page(url, delay=0.5):
data = {
    "cmd": "request.get",
    "url": url,
    "maxTimeout": 60000
}
headers = {"Content-Type": "application/json"}
time.sleep(delay)
print(requests.get("***:8191/v1", headers=headers, data=data))
return BeautifulSoup(requests.get("***:8191/v1", headers=headers, data=data).text, 'lxml')

答案1

得分: 0

你的Python代码中正在使用GET请求,应该改为POST请求。使用requests.post

英文:

you are using a GET request in your python code. It should be a POST request. Use requests.post

huangapple
  • 本文由 发表于 2023年6月1日 18:23:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380934.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定