gpt4 book ai didi

Python请求在localhost返回504

转载 作者:行者123 更新时间:2023-12-04 11:01:28 25 4
gpt4 key购买 nike

我运行werkzeug服务器(通过Flask),并尝试通过请求lib连接到本地主机,并收到504错误,但是如果在浏览器中打开http://127.0.0.1:5000/-没问题。

我的代码:

import requests
r = requests.get('http://127.0.0.1:5000/')
print(r.content)

响应错误:

b'\r\n\r\nERROR: Gateway Timeout\r\n

ERROR: Gateway Timeout

\r\n\r\n\r\n

While trying to retrieve the URL http://127.0.0.1:5000/:

\r\n
  • Connection refused
\r\n\r\n

Your cache administrator is webmaster.\r\n\r\nGenerated Thu, 06 Apr 2017 11:31:09 GMT by 10.101.0.1 (Mikrotik HttpProxy)\r\n\r\n'



flask 代码:
from flask import Flask, request, render_template, jsonify, Response
import geoLocation
import models
import json
from bson.json_util import dumps
from bson import json_util



app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
return 'OK'
....

如何通过请求库连接到本地主机(IP +端口)?

最佳答案

找到解决方案,禁用代理

import os
import requests

os.environ['NO_PROXY'] = '127.0.0.1'
r = requests.get('http://127.0.0.1:5000')
print(r.content)

关于Python请求在localhost返回504,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43254103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com