Skip to content

Commit 6d9ba51

Browse files
Merge pull request #220 from rctay/rc/191-ssl-gae
googleapiclient.http: guard when importing ssl.
2 parents 133b9ff + 3146c92 commit 6d9ba51

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

googleapiclient/http.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,18 @@
3838
import os
3939
import random
4040
import socket
41-
import ssl
4241
import sys
4342
import time
4443
import uuid
4544

45+
# TODO(issue 221): Remove this conditional import jibbajabba.
46+
try:
47+
import ssl
48+
except ImportError:
49+
_ssl_SSLError = object()
50+
else:
51+
_ssl_SSLError = ssl.SSLError
52+
4653
from email.generator import Generator
4754
from email.mime.multipart import MIMEMultipart
4855
from email.mime.nonmultipart import MIMENonMultipart
@@ -146,7 +153,7 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
146153
exception = None
147154
resp, content = http.request(uri, method, *args, **kwargs)
148155
# Retry on SSL errors and socket timeout errors.
149-
except ssl.SSLError as ssl_error:
156+
except _ssl_SSLError as ssl_error:
150157
exception = ssl_error
151158
except socket.error as socket_error:
152159
# errno's contents differ by platform, so we have to match by name.

0 commit comments

Comments
 (0)