Skip to content

Commit f1322af

Browse files
committed
fix qiniu upload on some time error node.
1 parent ba5ed37 commit f1322af

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

readme.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
cp -v wxagent/secfg.py.example wxagent/secfg.py
1818
vim wxagent/secfg.py
1919
python3 -m wxagent.wx2any
20-
20+
21+
22+
### TODOs
23+
24+
- [ ] python 3.5 type hint
25+
- [ ] replace ThreadPoolExecutor with asyncio
26+
- [ ] drop QThread thread
27+
- [ ] real multiple protocol IM room
28+
2129

2230
### Documentation
2331
[Proposal想法](https://github.com/kitech/wxagent/blob/master/doc/proposal.md)

wxagent/filestore.py

+27-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ def md5sum(data):
2525
return h.hexdigest()
2626

2727

28+
# need pyocclient-0.3 release
29+
class OwnCloudFileStor(FileStore):
30+
def __init__(self):
31+
return
32+
33+
def uploadData(data):
34+
return
35+
36+
def uploadFile(fname):
37+
return
38+
39+
2840
class QiniuFileStore(FileStore):
2941
def __init__(self):
3042
return
@@ -39,21 +51,24 @@ def uploadData(data):
3951
secret_key = qiniu_seckey
4052
bucket_name = qiniu_bucket_name
4153

54+
print(access_key, secret_key, bucket_name)
4255
q = qiniu.Auth(access_key, secret_key)
56+
# 由于本机时间错误,导致计算了出的token立即失效:
57+
# text_body:{"error":"expired token"}
58+
token = q.upload_token(bucket_name, expires=3600*24)
4359
key = 'helloqt.png'
4460
key = FileStore.md5sum(data)
4561
# data = 'hello qiniu!'
4662
# data = load_from_file(PATH)
47-
token = q.upload_token(bucket_name)
48-
print('uploading file:', key)
63+
print('uploading file:', key, token)
4964
ret, info = qiniu.put_data(token, key, data)
5065
if ret is not None:
5166
print('upload file All is OK', ret)
67+
url = 'http://7xn2rb.com1.z0.glb.clouddn.com/%s' % key
68+
return url
5269
else:
5370
print(ret, '=====', info) # error message in info
54-
55-
url = 'http://7xn2rb.com1.z0.glb.clouddn.com/%s' % key
56-
return url
71+
return str(info)
5772

5873
def uploadFile(fname):
5974
data = b''
@@ -63,6 +78,11 @@ def uploadFile(fname):
6378
return QiniuFileStore.uploadData(data)
6479

6580

81+
def _test_qiniu_upload():
82+
u = QiniuFileStore.uploadData('aaaaaaaaaaaaaaaaaaaaaaa'.encode())
83+
print(u)
84+
85+
6686
class ImgurFileStore(FileStore):
6787
def __init__(self):
6888
return
@@ -139,7 +159,7 @@ def __init__(self):
139159
return
140160

141161
def uploadData(data):
142-
# return 'nourl'
162+
return 'nourl'
143163
if type(data) == QByteArray:
144164
data = data.data()
145165

@@ -184,3 +204,4 @@ def uploadFile(fname):
184204
if not url.startswith('https://'): print('upload error: ', hdrval.getvalue())
185205

186206
return url
207+

wxagent/wxagent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def runfun() -> list:
7979
# Use body.encode('utf-8') if you want to send it encoded in UTF-8.
8080
res = self._sess.send(preq, timeout=35)
8181
# self.doreqcb(res if 'res' in locals() else None, req, reqid)
82-
except requests.ReadTimeout:
82+
except requests.exceptions.ReadTimeout:
8383
# TODO
8484
pass
8585
except Exception as ex:

0 commit comments

Comments
 (0)