Closed micahflee closed 2 years ago
I made it log the value of bridge_settings
and then reproduced the crash:
[May 30 2022 02:09:01 PM] CensorshipCircumvention.save_settings: bridge_settings: {'settings': None, 'country': 'us'}
Traceback (most recent call last):
File "/home/micah/code/onionshare/desktop/onionshare/connection_tab.py", line 263, in use_bridge_connect_clicked
if bridge_settings and self.censorship_circumvention.save_settings(
File "/home/micah/code/onionshare/cli/onionshare_cli/censorship.py", line 234, in save_settings
bridges = bridge_settings["settings"][0]["bridges"]
TypeError: 'NoneType' object is not subscriptable
It looks like if you're in the US (or other non-censored countries, presumably), the Censorship API returns None
for bridge settings.
Working on fixing this. It looks like instead of not returning a settings
key, it returns {"settings": None}
, so the fix it to check for both:
- if not "settings" in result:
+ if not "settings" in result or result["settings"] is None:
Ahh, yes, I think it was due to this upstream change: https://gitlab.torproject.org/tpo/anti-censorship/rdsys/-/issues/108#note_2800689 . They used to return just an empty {}
if no bridges to offer. Now they always return a populated dict with a country
key (whether or not there are bridges to offer), and therefore, they also return settings: []
in that scenario.
I actually wrote there that I didn't think it would cause a problem for us - looks like I was wrong!
Though I am still confused as I thought an empty []
would be treated as False in Python, apparently not.. at least not if it was a JSON []
..?
>>> [] == False
False
>>> [] == None
False
>>> False == None
False
>>> None == None
True
>>> if []:
... print("true?")
... else:
... print("false?")
...
false?
>>>
:)
I came across is bug while taking screenshots for the documentation. I disconnected from the internet, opened OnionShare, and tried to connect. Once it failed, I reconnected to the internet and then clicked "Automatically determine my country from my IP address for bridge settings".