我使用异步,请求和urllib被阻止

时间:2018-12-08 02:38:01

标签: python bots urllib

我将异步用于不和谐的bot,并且请求和urllib被阻止以获取Web内容。

  

忽略on_message中的异常   追溯(最近一次通话):     _run_event中的文件“ C:\ Users \ Hector Padro \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ discord \ client.py”,第307行       从getattr(self,event)(* args,** kwargs)的收益     文件“ C:\ Users \ Hector Padro \ Desktop \ bot.py”,第35行,位于on_message中       raw_json = urllib.request.urlopen(“ https://club-mice.com/yuir_lacasitos/api.php?user=” + mess.content [7:]。replace(“”,“%20”))。read()。decode()     urlopen中的文件“ C:\ Users \ Hector Padro \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ urllib \ request.py”,第223行       返回opener.open(URL,数据,超时)     打开的文件“ C:\ Users \ Hector Padro \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ urllib \ request.py”,第532行       响应= meth(req,响应)     http:// response中的文件“ C:\ Users \ Hector Padro \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ urllib \ request.py”,第642行       'http',请求,响应,代码,msg,hdr)     文件“ C:\ Users \ Hector Padro \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ urllib \ request.py”,第570行,错误       返回self._call_chain(* args)     _call_chain中的文件“ C:\ Users \ Hector Padro \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ urllib \ request.py”,第504行       结果= func(* args)     文件“ C:\ Users \ Hector Padro \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ urllib \ request.py”,第650行,位于http_error_default中       引发HTTPError(req.full_url,code,msg,hdrs,fp)   urllib.error.HTTPError:HTTP错误403:禁止

if mess.content.lower().startswith("!stats "):
    raw_json=urllib.request.urlopen("https://club-mice.com/yuir_lacasitos/api.php?user="+mess.content[7:].replace(" ", "%20")).read().decode()
    data=json.loads(raw_json)
    set_names={
        "name":"User",
        "gender":"Gender",
        "spouse":"Soul mate",
        "registration_date":"Registration date",
        "tribe":"Tribe",
        "level":"Level",
        "title":"Current title",
        "saved_mice":"Mice saved",
        "saved_mice_hard":"Mice saved in hard mode",
        "saved_mice_divine":"Mice saved in divine mode",
        "shaman_cheese":"Cheese personally gathered",
        "first":"Cheese gathered first",
        "cheese_gathered":"Gathered cheese",
        "bootcamp":"Bootcamps",
        "marriage_date":"Marriage",
    }
    message=""

我知道使用此tutorial可以解决我的问题,但是我对这些功能不太了解。

0 个答案:

没有答案