<p>I need to connect/send msg to <code>http://localhost:8001/path/to/my/service</code>, but I am not able to find how to do that. I know how to send if I only have <code>localhost</code> and <code>8001</code>, but I need this specific path <code>/path/to/my/service</code>. There is where my service is running.</p>
<pre class="lang-py prettyprint-override"><code>import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(&lt;full-url-to-my-service&gt;)
s.sendall(bytes('Message', 'utf-8'))
</code></pre>
<p><strong>Update</strong></p>
<p>My service is running on <code>localhost:8001/api/v1/namespaces/my_namespace/services/my_service:http/proxy</code>. How can I connect to it with <strong>python</strong>?</p>

<p>As @furas told in the comments</p>
<blockquote>
<p>socket is primitive object and it doesn't have specialized method for this - and you have to on your own create message with correct data. You have to learn HTTP protocol and use it to send</p>
</blockquote>
<p>This is a sample snippet to send a GET request in python using requests library</p>
<pre><code>import requests
URL = 'http://localhost:8001/path/to/my/service'
response_text = requests.get(URL).text
print(response_text)
</code></pre>
<p>This assumes the Content-Type that GET URL produces is text. If it is json, then a minor change is required</p>
<pre><code>import requests
URL = 'http://localhost:8001/path/to/my/service'
response_json = requests.get(URL).json()
print(response_json)
</code></pre>
<p>There are other ways to achieve the same using other good frameworks like urllib, and so on.
<a href="https://requests.readthedocs.io/en/master/" rel="nofollow noreferrer">Here</a> is the documentation of requests library for reference</p>
