Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def verifyDaemonIsAlive(hostAndPort):
"""Ensure that the IPFS daemon is running via HTTP before proceeding"""
try:
requests.get('http://' + hostAndPort)
except ConnectionError:
print('Daemon is not running at http://' + hostAndPort)
sys.exit()
def shutdown(self):
"""Stop the connected IPFS daemon instance.
Sending any further requests after this will fail with
``ipfshttpclient.exceptions.ConnectionError``, until you start another IPFS
daemon instance.
"""
try:
return self._client.request('/shutdown')
except exceptions.ConnectionError:
# Sometimes the daemon kills the connection before sending a
# response causing an incorrect `ConnectionError` to bubble
pass
def _do_request(self, *args, **kwargs):
for name, value in self._kwargs.items():
kwargs.setdefault(name, value)
try:
if self._session:
return self._session.request(*args, **kwargs)
else:
return requests.request(*args, **kwargs)
except (requests.ConnectTimeout, requests.Timeout) as error:
six.raise_from(exceptions.TimeoutError(error), error)
except requests.ConnectionError as error:
six.raise_from(exceptions.ConnectionError(error), error)
except http_client.HTTPException as error:
six.raise_from(exceptions.ProtocolError(error), error)
uri: URI
) -> Generator[Type[BaseURIBackend], None, None]:
# special case the default IPFS backend to the first slot.
default_ipfs = get_ipfs_backend_class()
if default_ipfs in ALL_URI_BACKENDS and default_ipfs().can_resolve_uri(uri):
yield default_ipfs
else:
for backend_class in ALL_URI_BACKENDS:
if backend_class is default_ipfs:
continue
# type ignored because of conflict with instantiating BaseURIBackend
else:
try:
if backend_class().can_resolve_uri(uri): # type: ignore
yield backend_class
except ConnectionError:
logger.debug(
"No local IPFS node available on port 5001.", exc_info=True
)
def stop(self):
"""Stop the connected IPFS daemon instance.
Sending any further requests after this will fail with
:class:`~ipfshttpclient.exceptions.ConnectionError`, until you start
another IPFS daemon instance.
"""
try:
return self._client.request('/shutdown')
except exceptions.ConnectionError:
# Sometimes the daemon kills the connection before sending a
# response causing an incorrect `ConnectionError` to bubble
pass
"""
Call the IPFS API to add the byte string to IPFS.
When IPFS returns a hash, return this to the caller
"""
global IPFS_API
# Returns unicode in py2.7, str in py3.7
try:
res = IPFS_API.add_bytes(bytes) # bytes)
except TypeError as err:
print('fail')
logError('IPFS_API had an issue pushing the item to IPFS')
logError(sys.exc_info())
logError(len(bytes))
traceback.print_tb(sys.exc_info()[-1])
except ipfsapi.exceptions.ConnectionError as connErr:
print('ConnErr')
logError(sys.exc_info())
traceback.print_tb(sys.exc_info()[-1])
return
# TODO: verify that the add was successful
if type(res).__name__ == 'unicode':
return res
elif type(res).__name__ == 'str':
return res
logError('NEITHER UNICODE NOR STR RETURNED.')
return res[0]['Hash']