-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoudao.py
More file actions
37 lines (31 loc) · 822 Bytes
/
youdao.py
File metadata and controls
37 lines (31 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# /usr/bin/env python
# coding=utf8
import httplib
import md5
import urllib
import random
appKey = '283bfbd98649b263'
secretKey = '6FFjLmOwMdukDj5kZdYm6RieIKPZPU7t'
httpClient = None
myurl = '/api'
q = 'prototype'
fromLang = 'EN'
toLang = 'zh-CHS'
salt = random.randint(1, 65536)
sign = appKey + q + str(salt) + secretKey
m1 = md5.new()
m1.update(sign)
sign = m1.hexdigest()
myurl = myurl + '?appKey=' + appKey + '&q=' + urllib.quote(q) + '&from=' + fromLang + '&to=' + toLang + '&salt=' + str(
salt) + '&sign=' + sign
try:
httpClient = httplib.HTTPConnection('openapi.youdao.com')
httpClient.request('GET', myurl)
# response是HTTPResponse对象
response = httpClient.getresponse()
print response.read()
except Exception, e:
print e
finally:
if httpClient:
httpClient.close()