Skip to content

可以兼容一下python2.7 #11

@Carliels

Description

@Carliels

master上的代码只需要修改IpGetter.py。 在python2.7版本中urllib.request对象不存在,可通过urllib2.urlopen(url)替代原有python3的urllib.request.urlopen(url)。 修改:

step1: 导包修改
`import sys
import json

if sys.version_info.major == 2:
#python2
import urllib2
else:
#python3
import urllib.request`

Step2: 添加通用url访问方法
def urlopen(url): if sys.version_info.major == 2: return urllib2.urlopen(url) else: return urllib.request.urlopen(url)

Step3: 替换文件用原有代码:response = urllib.request.urlopen(url) 为
response = urlopen(url)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions