我该如何解决此Python错误:无法建立连接,因为目标计算机主动拒绝了它

时间:2018-06-29 16:13:36

标签: python authentication auth0

下面是代码,每次我尝试运行此代码时,都会遇到相同的错误。我该如何解决?

package main

import (
    ...
)

type compressor struct {
    content []byte
}

func (r *compressor) compress() []byte {
    ...
}

func (r *compressor) decompress() []byte {
    var buffer bytes.Buffer
    dc := flate.NewReader(&buffer)
    _, err := dc.Read(r.content)
    if err != nil {
        if err != io.EOF {
            log.Fatal(err)
        }
    }

    return buffer.Bytes()
}

func main() {
    fileName := os.Args[1]
    fmt.Println(os.Args)
    contents, err := ioutil.ReadFile(fileName)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Print("Uncompressed data: ")
    fmt.Println(len(contents))

    comp := compressor{contents}
    buffer := comp.decompress()
    fmt.Print("Uncompressed data: ")
    fmt.Println(len(comp.decompress()))

    err = ioutil.WriteFile(fileName+".decjc", buffer, 0644)
    if err != nil {
        log.Fatal(err)
    }
}

1 个答案:

答案 0 :(得分:0)

我已经为这个问题苦苦了一段时间,但是当我将域传递给HTTPSConnection构造函数并将其从请求url中删除时,它终于起作用了,如下所示。归功于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"))