python - Golang 和 Python 执行 http 请求的方法之间的根本区别?

标签 python http go python-requests

这是我的问题:在 go 中执行与在 python 中相同的请求不会返回相同的 cookie,即使两者在同一端点上使用相同的 http 方法。这是我的 Python 代码:

import requests
r = requests.get("https://instagram.com/paperclip")
for cooke in r.cookies:
    print(cooke)

这按预期工作,应被视为控件。这是我的代码:

resp, err := http.Get("https://instagram.com/paperclip")
if err != nil {
    panic(err)
}

for _, cookie := range resp.Cookies() {
    fmt.Println(cookie.Name, cookie.Value)
}

唯一的区别是 golang 完全没有 cookie,我不确定为什么。有没有人以前经历过这种情况/知道为什么 golang 的行为不同?

编辑:如果相关:缺少的特定 cookie 是“urlgen="{[ip: port]}:[token of some kind]”

最佳答案

我已经在我的本地环境中尝试了您的代码,它工作得很好:

$ cat main.go 
package main

import (
    "fmt"
    "net/http"
)

func main() {
    resp, err := http.Get("https://instagram.com/paperclip")
    if err != nil {
        panic(err)
    }

    for _, cookie := range resp.Cookies() {
        fmt.Println(cookie.Name, cookie.Value)
    }

}

$ go run main.go 
urlgen {}:1gG5sj:plSKGgHYyLBefEhRrGVeZvPAs_M
mid W9MxTQAEAAGGiuN4IK97_H18ESVR
rur FRC
mcd 3
csrftoken LMddnPjpoVZB2p9X6bPJrGKWAzoMmMCO

$ go version
go version go1.11 darwin/amd64

关于python - Golang 和 Python 执行 http 请求的方法之间的根本区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52999399/

相关文章:

go - 如何在 Golang 中打印 slice 的内存地址?

python - 在插入或忽略后获取主键的 ID

python - 向后切片元组 - 如何处理获取第一个元素?

c# - 经过身份验证的调用

go - 为什么我的 Makefile 不在命令中插入表达式

error-handling - 如何检测 gorm 中的连接失败?

python - 如何在 Tensorflow 中以正确的方式使用自定义/非默认 tf.Graph?

python - 在 MSER 检测到的区域上执行凸包时出错

rest - 如果 Web Service Location 不断变化,可以使用哪种 Architecture

python - 在 Python Flask 应用程序中发送对 OPTIONS 的响应