我正在尝试使用这个简单的程序以接收模式将数据发送到私有 onionshare 服务器:
import socket
import requests
s = requests.session()
s.proxies['http'] = 'socks5h://127.0.0.1:9060'
s.proxies['https'] = 'socks5h://127.0.0.1:9060'
print(s.proxies)
url = 'http://*redacted*.onion'
headers = {
'Content-Type': 'application/json'
}
data = {
'key':'*redacted*'
}
try:
r = s.post(url, headers=headers, json=data, proxies=s.proxies)
print(r.text)
except Exception as e:
print(e)
我不断收到此错误:
SOCKSHTTPConnectionPool(host='*redacted*.onion', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSConnection object at 0x7fdf710c5a50>: Failed to establish a new connection: 0x01: General SOCKS server failure'))
尝试了以下方法:
https://www.facebookwkhpilnemxj7asaniu7vnjjbiltxjqhye3mhbshg7kx5tfyd.onion/
这有效。与仅卷曲它相同。
[notice] Fail to decrypt descriptor for requested onion address. It is likely requiring client authorization.
请注意,我不确定 OnionShare 服务器期望什么内容类型。不幸的是,我在查看他们的文档时发现很少关于此事的信息。
我解决了客户端授权的问题。问题是我的 .auth_private 文件中的格式。我在洋葱地址和 x25519 之间缺少“描述符”。我也对程序进行了很大的改变,并开始使用stem。通过这些更改,我设法通过 get 请求从 onionshare 页面获取 html。
from stem import Signal
from stem.control import Controller
import requests
def request_over_tor(url):
with Controller.from_port(port = 9061) as controller:
# Provide your authentication here if needed
# Signal Tor for a new circuit
controller.authenticate(password='*redacted*')
controller.signal(Signal.NEWNYM)
proxies = {
'http': 'socks5h://127.0.0.1:9060',
'https': 'socks5h://127.0.0.1:9060',
}
response = requests.get(url, proxies=proxies)
return response.text
hidden_service_url = 'http://*redacted*.onion'
response_content = request_over_tor(hidden_service_url)
print(response_content)