2017-09-21 3 views
0

저는 고객의 웹 사이트에 Google 캘린더를 구현해야합니다. 로그인 한 Google 계정에서 캘린더를 선택하고,보기/추가/수정/삭제할 수 있기를 원합니다.httplib.ResponseNotReady 액세스 토큰을 새로 고칠 때.

나는 예를 https://developers.google.com/api-client-library/python/auth/web-app을 (그래도 난 web2py 프레임 워크를 사용하지만, 그것은 아주 유사)

먼저 수행 한

- 모든 것이 내 로컬 컴퓨터에있는 모든 시간을 잘 작동; 두 번째로, 모든 것이 한 시간 동안 잘 작동하고 (드물게는 조금 더 많음), 중단 된 다음 프로덕션 서버에서 다시 작동하기 시작합니다.

나는 내 코드는 다음과 같이 간다 (나는 (희망)와 함께이 문제를 극복 한 후, 나는/고정 데이터를 암호화 작업을 것이다) 데이터베이스에 자격 증명을 저장하고있다 :

# just to show what "user.auth_user.google_credentials" is, from another function, where I do the oauth2callback stuff, and store it to the database 
def oauth2callback(): 
    ... 
    auth_code = request.vars['code'] 
    credentials = auth_flow.step2_exchange(auth_code) 
    db(db.auth_user.id == auth.user_id).update(google_credentials=credentials.to_json()) 
    redirect(URL(..)) 

# where it starts to fall apart 
credentials = client.OAuth2Credentials.from_json(user.auth_user.google_credentials) 
http_auth = credentials.authorize(httplib2.Http()) # fails here if access_token_expired 

calendar_service = discovery.build('calendar', 'v3', http=http_auth, cache_discovery=False) 
all_calendars = calendar_service.calendarList().list().execute() 

user_info_service = discovery.build('oauth2', 'v2', http=http_auth, cache_discovery=False) 
user_info = user_info_service.userinfo().get().execute() 

그때 반환 어떤 데이터는 뷰에, 옵션은 캘린더가있는 선택 상자를 생성하고, 선택 상자는 이벤트를 변경하고, 내가 가지고있는 다른 함수를 호출하여 선택한 달력의 이벤트를 가져옵니다.

def get_google_calendar_events(): 
    user = db(db.auth_user.id == auth.user_id).select().first() # retrieve logged in user from db 
    credentials = client.OAuth2Credentials.from_json(user.auth_user.google_credentials) 
    http_auth = credentials.authorize(httplib2.Http()) # also fails here if access token expired 
    calendar_id = request.vars.calendar_id # e.x. "primary" 
    calendar_service = discovery.build('calendar', 'v3', http=http_auth, cache_discovery=False) 
    events = calendar_service.events().list(calendarId=calendar_id, ...).execute() # I have more options here, but I doubt it's relevant, just min/max dates etc; 
    # Then I do some parsing, and just return the events where I apply styles, javascript, etc. 

나는에서 오류 얻을 : httplib.py 방법 "하는 GetResponse"선 ~ 1025; !

if self.__state != _CS_REQ_SENT 
# in my case, all failed cases were: 
"Idle" != "Request-sent" 
# self.__response was (probably?) correctly None 

나는 곳 디버깅에서 이동하는 아무 생각이 없다 "유휴"= "-전송 요청은"아마도 누군가가 알고 :

if self.__state != _CS_REQ_SENT or self.__response: 
    raise ResponseNotReady() 

내가 실패 곳임을 알아 냈어요?

내가 말했듯이 이것은 내 로컬 컴퓨터에서 항상 완벽하게 작동합니다. 흥미롭게도 ssh가 서버를 localhost로 터널링하면 완벽하게 작동합니다. 한 시간이 지나면 이러한 예외가 발생하기 시작하지만 몇 분이 지나면 다시 ~ Okayish 작업을 시작할 수 있습니다. 그러나 오류는 (임의의 양으로 보입니다);

나는 curl에 대한 경험이 없거나 내 자신의 요청을 작성하고 있지만,이 시점에서 나는 그것을 제공 할 생각이다. curl로 access_token을 새로 고칠 수 있습니까?

자바 스크립트로 모든 내용 다시 쓰기는 옵션이 아닙니다.

죄송 텍스트의 벽을 여기에, 나는 이틀 동안 내 머리카락을 당길거야; 통찰력을 많이 얻었습니다!

P. 한 번의 작업으로 여러 "discovery.build"메서드가 있음을 보여 줬습니다. "user_info_service"를 삭제하려고 시도했습니다. 아무 소용이 없지만 뭔가 잘못되었을 수도 있습니다. 그래서 그것이 내가 떠난 이유입니다.

+0

시간이 많이 걸리고 많은 검색을 한 결과 포트 443을 사용하여 2a00 : 1450 : 400f : 808 :: 200a 주소로 소켓 연결을 시도하는 경우가 있음을 발견했습니다. 프로덕션 서버의 잘못된 ipv6 구성 이것은 아마 * 경우입니다. – user3930760

답변

0

솔루션을 찾을 수 없습니다 니펫에서, IPv6은 때로는 연결이 실패 소켓의 문제가 아니다 : "포장"소켓이되고

"errno를 0 오류" SSLSocket에 의해, 때로는 내가 except 블록/바보 같은 시도에 싸서, 핸드 쉐이크에 실패 ~ 라인 140ish의 ssl.py 파이썬 2.7.3 :

try: 
    self.do_handshake() 
except Exception, e: 
    print 'handshake err: {0}\n'.format(e) 

내가 얻을 : "핸드 쉐이크 오류 : [errno를 0] 오류 " do_handshake가 컴파일 된 C 이후 실제로 여기서 무엇을 할 것인가에 관해선 알 수 없습니다.

관련 문제