下面是代码,每次我尝试运行此代码时,都会遇到相同的错误。我该如何解决?
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)
}
}
答案 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"))