0

I have three docker containers running by this kind of docker command:

docker run --name node3 -p 4003:4001 --network my-net xxx -node-id 3 -http-addr 0.0.0.0:4001 -raft-addr node3:4002 -join http://node1:4001

and inside my python program I use requests module:

def post(post_url, query_strs):
    return requests.post(post_url, json=query_strs, allow_redirects=False)


def get(get_url):
    return requests.get(get_url)

def commit(query_str, node_url=None, read_policy=None):
    if not read_policy is None and read_policy != "strong":
        print("""[ERROR] read_policy only accepts two possibilities: "none", "strong", commit discarded.""")
        return
    queries_from_user.append(query_str)

    if not "SELECT" in query_str:
        # Since All write-requests must be sent to the leader of the cluster, the node_url will be ignored.
        post_url = "http://{node_url}/db/execute"\
            .format(
                node_url=node_url if node_url else cluster_info["leader"]
            )
        urls_from_queries.append(post_url)
    else:
        print(f"""[WARN]: node_url is not provided, default to config["leader"], q={query_str}.""")
        get_url = "http://{node_url}/db/query?level={policy}&q={q}"\
            .format(
                node_url=node_url if node_url else cluster_info["leader"],
                policy="none" if read_policy is None else read_policy,
                q=utils.requote_uri(query_str)
            )
        urls_from_queries.append(get_url)

where my connection settings is: (this will be passed to the above post and get)

my_config = {
    "leader": "node1:4001",
    "cluster": ["node1:4001", "node2:4001", "node3:4001"]
}

might not related to this question but to provide more context, here are some of parts of my program:

NODE_1, NODE_2, NODE_3 = 0, 1, 2
# ...
my_sdk.commit(f"""SELECT * FROM {table_name}""", my_config["cluster"][NODE_3])
my_sdk.commit(f"""SELECT COUNT(*) FROM {table_name}""", my_config["cluster"][NODE_3])
my_sdk.print_history_commits()
replies = my_sdk.execute_all()
my_sdk.print_replies(replies)

and I got errors:

Traceback (most recent call last):
  File "/usr/local/anaconda3/envs/xxx/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/anaconda3/envs/xxx/lib/python3.9/site-packages/urllib3/util/connection.py", line 73, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/local/anaconda3/envs/xxx/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
NeoZoom.lua
  • 2,269
  • 4
  • 30
  • 64
  • What exactly is the value of `post_url` and `get_url` when those functions are called? – larsks Jun 12 '21 at 01:27
  • @larsks: Nice point, added. See the `def commit` that follows. – NeoZoom.lua Jun 12 '21 at 01:28
  • Unfortunately nearly all of this code seems irrelevant, the only line we need is a single one with your exact `requests.post` parameters - which we can't deduct from here. If you provide that (and the result of the same via curl) then things become answerable. – Cireo Jun 12 '21 at 01:39
  • Does this answer your question? [What does this Python requests error mean?](https://stackoverflow.com/questions/15286288/what-does-this-python-requests-error-mean) – Cireo Jun 12 '21 at 01:40
  • 1
    Its a problem with your db connection string which we would have to see to help you. I'm guessing its because your not trying to connect to the containers service ip properly. Better off to use something like docker swarm to spin up multiple containers like this as it allows for easy interconnection of containerized services on localhost. – thekid77777 Jun 12 '21 at 02:52
  • @Cireo: No, unfortunately. – NeoZoom.lua Jun 12 '21 at 04:18
  • @Cireo: The parameters are: post_url=`http://localhost:4001/db/execute`, `query_strs=[ f"""SELECT * FROM {table_name} ]"""`, is there any part still vague for you? I think my problem is more on how to operate docker networking. – NeoZoom.lua Jun 12 '21 at 04:25
  • Wouldn't it be db/query in your code since there is a SELECT? Doesn't really matter for your error message. Can you curl localhost:4001? Are you sure it is http not https? – Cireo Jun 13 '21 at 08:44

0 Answers0