mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-26 06:25:58 -05:00
Add a CensorshipCircumventionError class that is raised if there's a requests exception connecting to the Tor API
This commit is contained in:
parent
5d8300df10
commit
a385e1ffed
@ -22,6 +22,12 @@ import requests
|
|||||||
from .meek import MeekNotRunning
|
from .meek import MeekNotRunning
|
||||||
|
|
||||||
|
|
||||||
|
class CensorshipCircumventionError(Exception):
|
||||||
|
"""
|
||||||
|
There was a problem connecting to the Tor CensorshipCircumvention API.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class CensorshipCircumvention(object):
|
class CensorshipCircumvention(object):
|
||||||
"""
|
"""
|
||||||
Connect to the Tor Moat APIs to retrieve censorship
|
Connect to the Tor Moat APIs to retrieve censorship
|
||||||
@ -84,6 +90,7 @@ class CensorshipCircumvention(object):
|
|||||||
if country:
|
if country:
|
||||||
data = {"country": country}
|
data = {"country": country}
|
||||||
|
|
||||||
|
try:
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
endpoint,
|
endpoint,
|
||||||
json=data,
|
json=data,
|
||||||
@ -109,6 +116,8 @@ class CensorshipCircumvention(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
raise CensorshipCircumventionError(e)
|
||||||
|
|
||||||
def request_settings(self, country=False, transports=False):
|
def request_settings(self, country=False, transports=False):
|
||||||
"""
|
"""
|
||||||
@ -135,6 +144,7 @@ class CensorshipCircumvention(object):
|
|||||||
data = {"country": country}
|
data = {"country": country}
|
||||||
if transports:
|
if transports:
|
||||||
data.append({"transports": transports})
|
data.append({"transports": transports})
|
||||||
|
try:
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
endpoint,
|
endpoint,
|
||||||
json=data,
|
json=data,
|
||||||
@ -171,6 +181,8 @@ class CensorshipCircumvention(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
raise CensorshipCircumventionError(e)
|
||||||
|
|
||||||
def request_builtin_bridges(self):
|
def request_builtin_bridges(self):
|
||||||
"""
|
"""
|
||||||
@ -179,6 +191,7 @@ class CensorshipCircumvention(object):
|
|||||||
if not self.api_proxies:
|
if not self.api_proxies:
|
||||||
return False
|
return False
|
||||||
endpoint = "https://bridges.torproject.org/moat/circumvention/builtin"
|
endpoint = "https://bridges.torproject.org/moat/circumvention/builtin"
|
||||||
|
try:
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
endpoint,
|
endpoint,
|
||||||
headers={"Content-Type": "application/vnd.api+json"},
|
headers={"Content-Type": "application/vnd.api+json"},
|
||||||
@ -203,6 +216,8 @@ class CensorshipCircumvention(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
raise CensorshipCircumventionError(e)
|
||||||
|
|
||||||
def save_settings(self, settings, bridge_settings):
|
def save_settings(self, settings, bridge_settings):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user