亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

bind:請求的地址在其上下文中無效

bind:請求的地址在其上下文中無效

Go
Helenr 2022-06-27 16:18:14
我在 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


查看完整回答
反對 回復 2022-06-27
  • 1 回答
  • 0 關注
  • 1220 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號