ElectrumX server jsonRPC authentication - python

Unable to connect to electrum server
Error:
HTTPConnectionPool(host='electrum.eff.ro', port=50002): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
Connection is done in python:
electrum wallet jsonRPC authentication
import requests
import json
def main():
url = "http://electrum.eff.ro:50002"
payload = json.dumps(
{
"id": 0,
"method": "server.version",
"params": ["1.9.5", "0.6"]
}
)
headers = {'content-type': "application/json", 'cache-control': "no-cache"}
try:
response = requests.request("POST", url, data=payload, headers=headers, auth=(rpc_user, rpc_password))
return json.loads(response.text)
except requests.exceptions.RequestException as e:
print(e)
except:
print('No response from Wallet, check Bitcoin is running on this machine')
rpc_user = 'foo'
rpc_password = 'bar'
if __name__ == "__main__":
answer = main()
Such an error is constantly displayed.
UPD:
Server:
url = "http://fortress.qtornado.com:443"
error:
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
if connect HTTPS:
url = "https://fortress.qtornado.com:443"
error:
HTTPSConnectionPool(host='fortress.qtornado.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1051)')))
How to connect using ssl certificate?

An example of a solution to a problem:
https://github.com/cluelessperson/grappler
Bitcoin Testnet
import grappler
from base58 import b58decode_check
from binascii import hexlify
from hashlib import sha256
import codecs
a = grappler.ElectrumXConnector(
# host="fortress.qtornado.com", # bitcoin mainnet
host='tn.not.fyi',
port=55002,
# port=443,
ssl=True,
timeout=5
)
OP_DUP = b'76'
OP_HASH160 = b'a9'
BYTES_TO_PUSH = b'14'
OP_EQUALVERIFY = b'88'
OP_CHECKSIG = b'ac'
DATA_TO_PUSH = lambda address: hexlify(b58decode_check(address)[1:])
sig_script_raw = lambda address: b''.join((OP_DUP, OP_HASH160, BYTES_TO_PUSH, DATA_TO_PUSH(address), OP_EQUALVERIFY, OP_CHECKSIG))
script_hash = lambda address: sha256(codecs.decode(sig_script_raw(address), 'hex_codec')).digest()[::-1].hex()
a.send("server.version")
a.send("server.banner")
a.send('blockchain.scripthash.get_balance', script_hash('mksHkTDsauAP1L79rLZUQA3u36J3ntLtJx'))
a.send('blockchain.scripthash.get_mempool', script_hash('mksHkTDsauAP1L79rLZUQA3u36J3ntLtJx'))
a.send('blockchain.scripthash.subscribe', script_hash('mksHkTDsauAP1L79rLZUQA3u36J3ntLtJx'))

Related

Python Requests Post - HTTPSConnectionPool Max retries exceeded

Hi I have a simple code hosted on my Flask server to POST to my API
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
try:
url = "apiv2.xxxxxxxx.com/testpost"
session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
response = session.post(url)
except Exception as e:
return str(e)
However, it caught an exception and the error message is as follows:
HTTPSConnectionPool(host='apiv2.drobaio.com', port=443): Max retries exceeded with url: /authuser/$2b$10$wLkkKBi9g/gAAAAABgqr74HzvCs09eVY4O4YvkvXlf6lNe0uk9QG3Qp4g0lKzmgVFwLdQ50K1hptKKyguR2RrZJNJJnOlUs0LnyaqgefZ04g==/gAAAAABgqr74tJyvGCcFEpw3fdcKALlZUv-RHi3u0hdJJtgUDCE0Ga3hqoilUPL6vu3iTDzt2NDfX8UgfrcgQQFr3IFnfSDq_g== (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',))
Does anyone know what's wrong? I don't think there's an issue with my code as I tried executing this on my own PC and it works.

How to solve HTTPSConnectionPool(host='graph.facebook.com', port=443): Max retries exceeded with url

I am trying to post something on Facebook
def make_post():
caption = post_caption()
url = (
f"https://graph.facebook.com/{config.page_id}/photos?"
f"caption={caption}&access_token={config.token}"
)
files = {
'image': open(pimage, "rb")
}
if config.dry_run:
return dummy_response
response = requests.post(url, files=files)
return response.json()
but it gave me this error
HTTPSConnectionPool(host='graph.facebook.com', port=443): Max retries exceeded with url: (Caused by NewConnectionError('urllib3.connection.HTTPSConnection object at 0x000001AD174AA5B0>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))
I have searched here in stackoverflow but I didn't find anything that works sorry I am new to this site, if I did anything wrong.

Get HTML content from onion links using the request library (Python 3)

I am trying to get the html code of onion websites using the requests library (or urllib.request). I tried diverse methods but none of them seemed to work properly.
At first, I simply tried to connect to a proxy using the requests library and get the HTML code of the facebook deep web:
import requests
session = requests.session()
session.proxie = {}
session.proxies['http'] = 'socks5h://localhost:9050'
session.proxies['https'] = 'socks5h://localhost:9050'
r = requests.get('https://facebookcorewwwi.onion/')
print(r.text)
However, when I do this, the connection to the proxy doesn't work (my IP stays the same with or without the proxy).
I get the following error:
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='facebookcorewwwi.onion', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x109e8b198>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
After doing some research, I saw someone who tried to do a similar thing and the solution was to connect to the proxy before importing the requests/urllib.request library.
So I tried connecting using the libraries socks and socket:
import socks
import socket
def create_connection(address, timeout=None, source_address=None):
sock = socks.socksocket()
sock.connect(address)
return sock
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
# patch the socket module
socket.socket = socks.socksocket
socket.create_connection = create_connection
import urllib.request
with urllib.request.urlopen('https://facebookcorewwwi.onion/') as response:
html = response.read()
print(html)
When I do this, my connection the the proxy gets refused:
urllib.error.URLError: <urlopen error Error connecting to SOCKS5 proxy 127.0.0.1:9050: [Errno 61] Connection refused>
I tried to use the requests library instead like follow (simply replace it from the line that says import urllib.request)
import requests
r = requests.get('https://facebookcorewwwi.onion/')
print(r.text)
But here I get this error:
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='facebookcorewwwi.onion', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10d93ee80>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
It seem that no matter what I do my connection to a proxy gets refused. Does anyone have an alternative solution or a way to fix this?

Failed to establish a new connection error using Python requests Errno -2 Name or service unknown

I am trying to make a request to an API with Python. I am able to make the request with curl without issue but I have something wrong with my Python request.
Why does this code,
import requests
from requests.auth import HTTPBasicAuth
emailadd = 'user123#example.com'
domain = 'example.com'
spantoken = 'omitted'
def checkUserLicensed(useremail):
url = ('https://api.spannigbackup.com/v1/users/' + useremail)
print(url)
response = requests.get(url, auth=(domain,spantoken))
print(response)
checkUserLicensed(emailadd)
Return this error
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.spannigbackup.com', port=443): Max retries exceeded with url: /v1/users/user123#example.com
(Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f73ca323748>: Failed to establish a new connection: [Errno -2] Name or service not known'))

Error 10054 when connecting google service

I tried to connect to google api and got this error
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: /speech-api/v1/recognize?xjerr=1&client=chromium&lang=ru-RU (Caused by <class 'socket.error'>: [Errno 10054] An existing connection was forcibly closed by the remote host)
this is my code, i used library urllib3,urllib2,requests but it did not help
import requests
recording = 'C:/Users/sborovskiy/PycharmProjects/VoiceManager/com/work/voiceManager/output.flac'
url = 'https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=ru-RU'
headers = {'Content-Type' : 'audio/x-flac; rate=16000', 'User-Agent': 'Netscape 6.0'}
files = {'output.flac' : open(recording, 'rb')}
response = requests.post(url = url, data = files, headers = headers)
internet not give a specific answer

Categories