Ashley Garner
Ashley Garner

Reputation: 51

How do I solve this python error: No connection could be made because the target machine actively refused it

The code is below and every time I try to run this code I get the same error. How do I solve this?

import http.client

conn = http.client.HTTPSConnection("")

headers = { 'authorization': "Bearer YOUR_ACCESS_TOKEN" }

conn.request("GET", "/violetwears.auth0.com/api/v2/users/USER_ID", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

Upvotes: 1

Views: 567

Answers (1)

Maciej
Maciej

Reputation: 2185

I was struggling with this issue for a while now but it finally worked when I passed the domain to the HTTPSConnection constructor and remove it from the request url as follows. Credit to the answer here on auth0 community

import http.client

conn = http.client.HTTPSConnection("violetwears.auth0.com")

headers = { 'authorization': "Bearer YOUR_ACCESS_TOKEN" }

conn.request("GET", "/api/v2/users/USER_ID", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

Upvotes: 2

Related Questions