I\'m attempting to make use of cgminer
\'s API using Python. I\'m particularly interested in utilizing the requests
library.
I understand how to
As someone who has learned some of the common pitfalls of python networking the hard way, I'm adding this answer to emphasize an important-but-easy-to-mess-up point about the 1st arg of requests.get()
:
localhost
is an alias which your computer resolves to 127.0.0.1
, the IP address of its own loopback adapter. foo.com
is also an alias, just one that gets resolved further away from the host.
requests.get('foo.com:4028') #<--fails
requests.get('http://foo.com:4028') #<--works usually
& for loopbacks:
requests.get('http://127.0.0.1:4028') #<--works
requests.get('http://localhost:4028') #<--works
this one requires import socket
& gives you the local ip of your host (aka, your address within your own LAN); it goes a little farther out from the host than just calling localhost
, but not all the way out to the open-internet:
requests.get('http://{}:4028'.format(socket.gethostbyname(socket.gethostname()))) #<--works