方法不允许,flask,python

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

Method not allowed, flask, python

问题

已在Docker中安装了FlareSolverr。

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

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

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

  1. def get_parsed_page(url, delay=0.5):
  2. data = {
  3. "cmd": "request.get",
  4. "url": url,
  5. "maxTimeout": 60000
  6. }
  7. headers = {"Content-Type": "application/json"}
  8. time.sleep(delay)
  9. print(requests.get("***:8191/v1", headers=headers, data=data))
  10. return BeautifulSoup(requests.get("***:8191/v1", headers=headers, data=data).text, 'lxml')

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

英文:

Installed FlareSolverr in docker.

cURL work correctly and return the correct response.

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

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

  1. def get_parsed_page(url, delay=0.5):
  2. data = {
  3. "cmd": "request.get",
  4. "url": url,
  5. "maxTimeout": 60000
  6. }
  7. headers = {"Content-Type": "application/json"}
  8. time.sleep(delay)
  9. print(requests.get("***:8191/v1", headers=headers, data=data))
  10. 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:

确定