DetailedApiRequestError(status: 401, message: Login Required)
我使用了googleapis身份验证包,但显示错误
import socket
import os
import hashlib
import buffer
HOST = '127.0.0.1'
PORT = 2345
def getHash(fileName, hashType):
... hash algorithms ....
try:
os.mkdir('uploads')
except FileExistsError:
pass
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(10)
print("Waiting for a connection.....")
while True:
conn, addr = s.accept()
print("Got a connection from ", addr)
connbuf = buffer.Buffer(conn)
while True:
hash_type = connbuf.get_utf8()
if not hash_type:
break
print('Hash Type: ', hash_type)
file_name = connbuf.get_utf8()
if not file_name:
break
print('File Name: ', file_name)
file_name = os.path.join('uploads', file_name)
file_size = connbuf.get_utf8()
file_size = int(file_size)
print('File Size: ', file_size)
with open(file_name, 'wb') as f:
remaining = file_size
while remaining:
if remaining >= 4096:
chunk_size = 4096
else:
chunk_size = remaining
chunk = connbuf.get_bytes(chunk_size)
if not chunk:
break
f.write(chunk)
remaining -= len(chunk)
if remaining:
print('File incomplete: MISSING', remaining, 'BYTES.')
else:
print('File received successfully.')
file_hash = getHash(file_name, hash_type)
response = file_name + ' ' + file_hash
connbuf.put_utf8(response)
print('Connection closed.')
conn.close()