Skip to content

Commit

Permalink
Ropsten API URL changed and the normal requests are blocked with a 40…
Browse files Browse the repository at this point in the history
…3 if the User Agent is python-requests.
  • Loading branch information
antonellopasella committed Jul 28, 2021
1 parent 6b4879a commit 5a4b7da
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cert_issuer/blockchain_handlers/ethereum/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
if hasattr(app_config, 'ropsten_rpc_url'):
self.ropsten_rpc_url = app_config.ropsten_rpc_url
rop_provider_list.append(EthereumRPCProvider(self.ropsten_rpc_url))
rop_provider_list.append(EtherscanBroadcaster('https://ropsten.etherscan.io/api', etherscan_api_token))
rop_provider_list.append(EtherscanBroadcaster('https://api-ropsten.etherscan.io/api', etherscan_api_token))
# rop_provider_list.append(MyEtherWalletBroadcaster('https://api.myetherwallet.com/rop', None))
self.connectors[Chain.ethereum_ropsten] = rop_provider_list

Expand Down Expand Up @@ -162,7 +162,8 @@ def broadcast_tx(self, tx):
broadcast_url = self.base_url + '?module=proxy&action=eth_sendRawTransaction'
if self.api_token:
broadcast_url += '&apikey=%s' % self.api_token
response = requests.post(broadcast_url, data={'hex': tx_hex})
response = requests.post(broadcast_url, data={'hex': tx_hex}, headers={'user-agent':'cert-issuer'})

if 'error' in response.json():
logging.error("Etherscan returned an error: %s", response.json()['error'])
raise BroadcastError(response.json()['error'])
Expand All @@ -185,7 +186,7 @@ def get_balance(self, address):
broadcast_url += '&tag=pending'
if self.api_token:
broadcast_url += '&apikey=%s' % self.api_token
response = requests.get(broadcast_url)
response = requests.get(broadcast_url, headers={'user-agent':'cert-issuer'})
if int(response.status_code) == 200:
if response.json().get('message', None) == 'NOTOK':
raise BroadcastError(response.json().get('result', None))
Expand All @@ -204,7 +205,7 @@ def get_address_nonce(self, address):
broadcast_url += '&tag=pending' # Valid tags are 'earliest', 'latest', and 'pending', the last of which includes both pending and committed transactions.
if self.api_token:
broadcast_url += '&apikey=%s' % self.api_token
response = requests.get(broadcast_url, )
response = requests.get(broadcast_url, headers={'user-agent':'cert-issuer'})
if int(response.status_code) == 200:
if response.json().get('message', None) == 'NOTOK':
raise BroadcastError(response.json().get('result', None))
Expand All @@ -228,7 +229,7 @@ def broadcast_tx(self, tx):
"params": ["0x" + tx],
"id": 1
}
response = requests.post(self.base_url, json=data)
response = requests.post(self.base_url, json=data, headers={'user-agent':'cert-issuer'})
if 'error' in response.json():
logging.error("MyEtherWallet returned an error: %s", response.json()['error'])
raise BroadcastError(response.json()['error'])
Expand All @@ -250,7 +251,7 @@ def get_balance(self, address):
"params": [address, "latest"],
"id": 1
}
response = requests.post(self.base_url, json=data)
response = requests.post(self.base_url, json=data, headers={'user-agent':'cert-issuer'})
if int(response.status_code) == 200:
logging.info('Balance check response: %s', response.json())
balance = int(response.json().get('result', None), 0)
Expand All @@ -271,7 +272,7 @@ def get_address_nonce(self, address):
"params": [address, "pending"],
"id": 1
}
response = requests.post(self.base_url, json=data)
response = requests.post(self.base_url, json=data, headers={'user-agent':'cert-issuer'})
if int(response.status_code) == 200:
# the int(res, 0) transforms the hex nonce to int
nonce = int(response.json().get('result', None), 0)
Expand Down

0 comments on commit 5a4b7da

Please sign in to comment.