Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caucase
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vincent Pelletier
caucase
Commits
b5eab640
Commit
b5eab640
authored
Feb 02, 2021
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: Catch SSL errors.
parent
3751896f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
caucase/client.py
caucase/client.py
+25
-4
No files found.
caucase/client.py
View file @
b5eab640
...
@@ -36,6 +36,8 @@ from . import version
...
@@ -36,6 +36,8 @@ from . import version
__all__
=
(
__all__
=
(
'CaucaseError'
,
'CaucaseError'
,
'CaucaseHTTPError'
,
'CaucaseSSLError'
,
'CaucaseClient'
,
'CaucaseClient'
,
'HTTPSOnlyCaucaseClient'
,
'HTTPSOnlyCaucaseClient'
,
)
)
...
@@ -43,11 +45,23 @@ __all__ = (
...
@@ -43,11 +45,23 @@ __all__ = (
_cryptography_backend
=
default_backend
()
_cryptography_backend
=
default_backend
()
class
CaucaseError
(
Exception
):
class
CaucaseError
(
Exception
):
"""
Base error for errors when communicating with a caucase server.
"""
pass
class
CaucaseHTTPError
(
CaucaseError
):
"""
"""
Raised when server responds with an HTTP error status.
Raised when server responds with an HTTP error status.
"""
"""
pass
pass
class
CaucaseSSLError
(
CaucaseError
):
"""
Raised when there is an SSL error while communicating with the server.
"""
pass
class
CaucaseClient
(
object
):
class
CaucaseClient
(
object
):
"""
"""
Caucase HTTP(S) client.
Caucase HTTP(S) client.
...
@@ -171,11 +185,18 @@ class CaucaseClient(object):
...
@@ -171,11 +185,18 @@ class CaucaseClient(object):
path
=
self
.
_path
+
url
path
=
self
.
_path
+
url
headers
=
headers
or
{}
headers
=
headers
or
{}
headers
.
setdefault
(
'User-Agent'
,
'caucase '
+
version
.
__version__
)
headers
.
setdefault
(
'User-Agent'
,
'caucase '
+
version
.
__version__
)
try
:
connection
.
request
(
method
,
path
,
body
,
headers
)
connection
.
request
(
method
,
path
,
body
,
headers
)
response
=
connection
.
getresponse
()
response
=
connection
.
getresponse
()
response_body
=
response
.
read
()
response_body
=
response
.
read
()
except
ssl
.
SSLError
as
exc
:
raise
CaucaseSSLError
(
exc
.
errno
,
exc
.
strerror
)
if
response
.
status
>=
400
:
if
response
.
status
>=
400
:
raise
CaucaseError
(
response
.
status
,
response
.
getheaders
(),
response_body
)
raise
CaucaseHTTPError
(
response
.
status
,
response
.
getheaders
(),
response_body
,
)
assert
response
.
status
<
300
# caucase does not redirect
assert
response
.
status
<
300
# caucase does not redirect
if
response
.
status
==
201
:
if
response
.
status
==
201
:
return
response
.
getheader
(
'Location'
)
return
response
.
getheader
(
'Location'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment