我在 golang 上開發了一個機器人。使用 ubuntu 20.01 OS 在 vds 上啟動它,效果很好,但是當我開始調試我的代碼時,這是一個問題。因此,我決定將我的 PC 用作 VDS:我打開了一個8443端口等。但是當main.go啟動時,我收到一個錯誤:listen tcp [ip]:8443: bind: The requested address is not valid in its context.我的代碼:package mainimport ( "./configuration" "./get_data" "encoding/json" "fmt" tgBotApi "github.com/go-telegram-bot-api/telegram-bot-api" "io/ioutil" "net/http" "strings" "time")var ( NewBot, BotErr = tgBotApi.NewBotAPI(configuration.BOT_TOKEN))func setWebhook(bot *tgBotApi.BotAPI) { webHookInfo := tgBotApi.NewWebhookWithCert(fmt.Sprintf("https://%s:%s/%s", configuration.BOT_HOST, configuration.BOT_PORT, configuration.BOT_TOKEN), configuration.CERT_FILE) _, err := bot.SetWebhook(webHookInfo) if err != nil { fmt.Println(err) }}func main () { fmt.Println("OK", time.Now().Unix(), time.Now(), time.Now().Weekday()) setWebhook(NewBot) message := func (w http.ResponseWriter, r *http.Request) { text, _ := ioutil.ReadAll(r.Body) var botText = get_data.BotMessage{} _ = json.Unmarshal(text, &botText) chatGroup := int64(botText.Message.Chat.Id) botCommand := strings.Split(botText.Message.Text, "@")[0] /*markup := tgBotApi.InlineKeyboardMarkup{ InlineKeyboard: [][]tgBotApi.InlineKeyboardButton{ []tgBotApi.InlineKeyboardButton{ tgBotApi.InlineKeyboardButton{Text: "start"}, }, },我已經成了類似本主題的證書:為 Telegram Webhook 創建和使用自簽名證書的簡單方法是什么?此外,我試圖設置 0.0.0.0 而不是我的公共 IP,然后出現此錯誤:Bad Request: bad webhook: IP address 0.0.0.0 is reserved
1 回答

婷婷同學_
TA貢獻1844條經驗 獲得超8個贊
該錯誤bind: The requested address is not valid in its context.
表明該地址不屬于您機器上的網絡接口。很可能,有一個路由器/負載平衡器/等......具有實際的公共地址,它將流量轉發到您的機器。
您需要拆分您使用的地址:
您的本地地址(請參閱
ifconfig
)或0.0.0.0
所有接口作為傳遞給的地址http.ListenAndServeTLS
傳入的作為回調地址的公共地址
NewWebhookWithCert
- 1 回答
- 0 關注
- 1220 瀏覽
添加回答
舉報
0/150
提交
取消