遇到问题--python--爬虫--urllib的post参数类型错误--传输json格式

情况

使用代码

def fetch_raw_post_meitu(link, data):
    proxy_support = urllib.request.ProxyHandler({'https': '192.168.11.195:8888'})
    opener = urllib.request.build_opener(proxy_support)

    urllib.request.install_opener(opener)
    user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
    headers = {'User-Agent': user_agent, "Content-Type": "application/json; charset=UTF-8"}
    # headers = {"timestamp": utc_datetime_to_timestamp(datetime.utcnow()), "User-Agent": "okhttp/3.10.0", "channel": "setup","sdk-type": "universal", "language": "zh", "locale": "%E4%B8%AD%E5%9B%BD", "Content-Type": "application/json; charset=UTF-8"}
    print({'data': json.dumps(data)})
    print({'headers': json.dumps(headers)})
    params = urllib.parse.urlencode(data).encode('utf-8')
    r = urllib.request.Request(link, data=params, headers=headers)
    response = urllib.request.urlopen(r, timeout=6)
    the_page = response.read()
    content = the_page.decode("

你可能感兴趣的:(python,数据采集,遇到问题解决方案集锦,数据采集)