Open taoxiaoxin1688-dev opened 1 week ago
Happening in my app too and it's quite severe. I can't put my finger on it but I suspect more issues coming from the latest fastapi. It seems fastapi's including httptools and dnspython now which the older versions did not. I seem to have solved this issues by forcing fastapi back to 0.103.0 but I'm not certain it's really gone.
What's the workaround, still getting this with 4.43?
` What's the workaround, still getting this with 4.43?
This is what I've done so far, adding this code at the very beginning when using gradio, it's much better and the program rarely gets network errors.
import socket
from gradio import analytics
def get_local_ip_address():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip_address = s.getsockname()[0]
s.close()
except:
ip_address = "127.0.0.1"
return ip_address
def _do_normal_analytics_request(data, topic): # 添加 topic 参数
try:
data["ip_address"] = get_local_ip_address()
# 如果你想完全禁用网络请求,可以在这里直接返回
print(f"Analytics request for topic '{topic}' with data: {data}")
return
except Exception as e:
print(f"Analytics request failed for topic '{topic}': {str(e)}")
# 应用猴子补丁
analytics.get_local_ip_address = get_local_ip_address
analytics._do_normal_analytics_request = _do_normal_analytics_request
But you can completely turn off gradio analytics and it still happens!
os.environ['GRADIO_ANALYTICS_ENABLED'] = '0'
But you can completely turn off gradio analytics and it still happens!
os.environ['GRADIO_ANALYTICS_ENABLED'] = '0'
Write about your program, this is so cool, I'll just disable it and it won't report an error
Just to confirm, everyone here is seeing these errors only on machines that do not have internet access?
Just to confirm, everyone here is seeing these errors only on machines that do not have internet access?
No, for me it's also happening on a machine with internet access. I can't really put my finger on it but disabling analytics doesn't do anything for me 😞 I have 2 machines I'm testing my app on and the most noticeable difference is performance. Since upgrading to 4.43 and forcing an older fastapi version the error doesn't happen anymore on the faster pc whereas it almost always happens on the slower one where events take a lot longer. I noticed 1 thing though. If the connection error happened and you just refresh the page, it won't ever happen again in that session. Perhaps that is helping? Btw. I'm using Firefox on both machines, eventually it's a browser issue? Also, I've noticed newer fastapi versions include httptools and dnstools...I don't know if there's a link. Thanks for trying to help!
Describe the bug
When using gradio on a server without a network environment, there will be network errors. See the log for specific error information. Every time I have to use the monkey patch to deal with this error, sometimes it doesn't work.
Have you searched existing issues? 🔎
Reproduction
Screenshot
Logs
System Info
Severity
I can work around it