python微信开发

yun_gongzi 发布于 2016/11/10 22:14
阅读 446
收藏 0

@Kevin_Yang 你好,想跟你请教个问题:

看您的教程:https://my.oschina.net/yangyanxing/blog/194136

微信开发小翻译,遇到如下问题:

Traceback (most recent call last):   File "D:/LearnPython/LearnPy/youdao.py", line 34, in <module>
    print youdao(Neword)
  File "D:/LearnPython/LearnPy/youdao.py", line 17, in youdao
    fanyi = json.loads(resp.read())
  File "C:\Python27\lib\json\__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
这是单独把程序拿出来测试的,程序如下:

# -*- coding: UTF-8 -*-

import urllib2 

import json



def youdao(word):
    qword = urllib2.quote(word)
    baseur1 = r'http://fanyi.youdao.com/openapi.do?keyfrom=pythontry1&key=1203296434&type=data&doctype=json&version=1.1&q='
    url = baseur1 + qword
    resp = urllib2.urlopen(url)
    fanyi = json.loads(resp.read())
        
    if 'basic' in fanyi.keys():
        trans = u'%s: %s  %s\n网络释义: %s' % (fanyi['query'],''.join(fanyi['translation']),''.join(fanyi['basic']['explains']),''.join(fanyi['web'][0]['value']))
        return trans
    else:
        return u'对不起,您输入的单词%s无法翻译' % word




while True:
    Neword = raw_input('输入单词或词语:')
    if Neword == '.':
        break
    else:
        print youdao(Neword)
可以翻译英文,输入中文时会出现以上错误。

我用的是新浪云服务器,实际测试时,微信手机端输入任何文本都会提示,‘暂时无法服务’

跪求大神指点!!!

菜鸟不胜感激!!!


加载中
返回顶部
顶部