英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论