Reputation: 177
I am having trouble on osx specifically with this, running High Sierra.
The problem is that in the following code the call to requests.get doesn't do anything. It doesn't make it out of the call at all, and also does not raise an error. The print method after the get call doesn't get executed, but the app does not crash, it just continues on to the main loop like nothing happened.
This same code runs fine on linux. I am working out how I can try it on windows and also hopefully another install of osx.
I am at a complete loss here. The fact that it doesn't even raise an error is strange to me.
import tkinter as tk
from tkinter import ttk
import multiprocessing
import time
import requests
class SplashScreen(tk.Toplevel):
def __init__(self, root):
super(SplashScreen, self).__init__(root)
self.width = 800
self.height = 400
self.geometry('{Width}x{Height}'.format(Width=self.width, Height=self.height))
self.overrideredirect(True)
self.label = ttk.Label(self, text='My Splash', anchor='center')
self.label.grid(column=0, row=2)
def destroy_splash_screen(self):
self.destroy()
print('destroyed splash')
class App(tk.Tk):
def __init__(self):
super(App, self).__init__()
self.splash = SplashScreen(self)
self.withdraw()
process_startup = multiprocessing.Process(
target=self.startup_process,
args=("stuff",)
)
process_startup.start()
self.splash.update()
while process_startup.is_alive():
time.sleep(0.1)
self.title("MyApp")
self.mainloop()
def mainloop(self, n=0):
first_loop = True
while True:
self.update_idletasks()
self.update()
if first_loop:
self.remove_splash_screen()
first_loop = False
def startup_process(self, things):
init_client()
def remove_splash_screen(self):
self.splash.destroy_splash_screen()
del self.splash
self.deiconify()
def init_client():
requests.get("http://httpbin.org/ip")
s = 'strfff'
print(s)
if __name__ == '__main__':
app = App()
Also if I follow it through with the debugger it enters the black hole at this point in the requests library.
def should_bypass_proxies(url, no_proxy):
"""
Returns whether we should bypass proxies or not.
:rtype: bool
"""
# Prioritize lowercase environment variables over uppercase
# to keep a consistent behaviour with other http projects (curl, wget).
get_proxy = lambda k: os.environ.get(k) or os.environ.get(k.upper())
# First check whether no_proxy is defined. If it is, check that the URL
# we're getting isn't in the no_proxy list.
no_proxy_arg = no_proxy
if no_proxy is None:
no_proxy = get_proxy('no_proxy')
parsed = urlparse(url)
if parsed.hostname is None:
# URLs don't always have hostnames, e.g. file:/// urls.
return True
if no_proxy:
# We need to check whether we match here. We need to see if we match
# the end of the hostname, both with and without the port.
no_proxy = (
host for host in no_proxy.replace(' ', '').split(',') if host
)
if is_ipv4_address(parsed.hostname):
for proxy_ip in no_proxy:
if is_valid_cidr(proxy_ip):
if address_in_network(parsed.hostname, proxy_ip):
return True
elif parsed.hostname == proxy_ip:
# If no_proxy ip was defined in plain IP notation instead of cidr notation &
# matches the IP of the index
return True
else:
host_with_port = parsed.hostname
if parsed.port:
host_with_port += ':{}'.format(parsed.port)
for host in no_proxy:
if parsed.hostname.endswith(host) or host_with_port.endswith(host):
# The URL does match something in no_proxy, so we don't want
# to apply the proxies on this URL.
return True
with set_environ('no_proxy', no_proxy_arg):
# parsed.hostname can be `None` in cases such as a file URI.
try:
# It executes this method and returns when stepped through but from here it just ends. doesn't go anywhere from this point
bypass = proxy_bypass(parsed.hostname)
except (TypeError, socket.gaierror):
bypass = False
if bypass:
return True
return False
This code is in requests/utils.py
Any ideas on where to start with this. Like I said I am at a complete loss right now.
Upvotes: 2
Views: 325
Reputation: 11
Check this:
from sys import platform
if platform == "darwin":
os.environ['no_proxy'] = '*'
In my case this solution works for MacOSx.
Refer: requests: how to disable / bypass proxy
Upvotes: 0
Reputation: 17008
It seems that requests
on MacOS is a bit buggy. Try to disable the proxies by setting trust_env
to False
:
session = requests.Session()
session.trust_env = False # No proxy settings from the OS
r = session.get(url)
Upvotes: 1