Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
b6e9e7a4
Commit
b6e9e7a4
authored
Aug 06, 2012
by
kimth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle network errors more gracefully
parent
ae11f918
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
common/lib/capa/capa/xqueue_interface.py
+13
-12
No files found.
common/lib/capa/capa/xqueue_interface.py
View file @
b6e9e7a4
...
@@ -61,7 +61,7 @@ class XqueueInterface:
...
@@ -61,7 +61,7 @@ class XqueueInterface:
def
__init__
(
self
,
url
=
XQUEUE_URL
,
auth
=
XQUEUE_LMS_AUTH
):
def
__init__
(
self
,
url
=
XQUEUE_URL
,
auth
=
XQUEUE_LMS_AUTH
):
self
.
url
=
url
self
.
url
=
url
self
.
auth
=
auth
self
.
auth
=
auth
self
.
s
=
requests
.
session
()
self
.
s
ession
=
requests
.
session
()
self
.
_login
()
self
.
_login
()
def
send_to_queue
(
self
,
header
,
body
,
file_to_upload
=
None
):
def
send_to_queue
(
self
,
header
,
body
,
file_to_upload
=
None
):
...
@@ -86,30 +86,31 @@ class XqueueInterface:
...
@@ -86,30 +86,31 @@ class XqueueInterface:
return
(
error
,
msg
)
return
(
error
,
msg
)
def
_login
(
self
):
def
_login
(
self
):
try
:
payload
=
{
'username'
:
self
.
auth
[
'username'
],
r
=
self
.
s
.
post
(
self
.
url
+
'/xqueue/login/'
,
data
=
{
'username'
:
self
.
auth
[
'username'
],
'password'
:
self
.
auth
[
'password'
]
}
'password'
:
self
.
auth
[
'password'
]
})
return
self
.
_http_post
(
self
.
url
+
'/xqueue/login/'
,
payload
)
except
requests
.
exceptions
.
ConnectionError
,
err
:
log
.
error
(
err
)
return
(
1
,
'cannot connect to server'
)
return
parse_xreply
(
r
.
text
)
def
_send_to_queue
(
self
,
header
,
body
,
file_to_upload
=
None
):
def
_send_to_queue
(
self
,
header
,
body
,
file_to_upload
=
None
):
payload
=
{
'xqueue_header'
:
header
,
payload
=
{
'xqueue_header'
:
header
,
'xqueue_body'
:
body
}
'xqueue_body'
:
body
}
files
=
None
files
=
None
if
file_to_upload
is
not
None
:
if
file_to_upload
is
not
None
:
files
=
{
file_to_upload
.
name
:
file_to_upload
}
files
=
{
file_to_upload
.
name
:
file_to_upload
}
return
self
.
_http_post
(
self
.
url
+
'/xqueue/submit/'
,
payload
,
files
)
def
_http_post
(
self
,
url
,
data
,
files
=
None
):
try
:
try
:
r
=
self
.
s
.
post
(
self
.
url
+
'/xqueue/submit/'
,
data
=
payload
,
files
=
files
)
r
=
self
.
s
ession
.
post
(
url
,
data
=
data
,
files
=
files
)
except
requests
.
exceptions
.
ConnectionError
,
err
:
except
requests
.
exceptions
.
ConnectionError
,
err
:
log
.
error
(
err
)
log
.
error
(
err
)
return
(
1
,
'cannot connect to server'
)
return
(
1
,
'cannot connect to server'
)
if
r
.
status_code
not
in
[
200
]:
return
(
1
,
'unexpected HTTP status code [
%
d]'
%
r
.
status_code
)
return
parse_xreply
(
r
.
text
)
return
parse_xreply
(
r
.
text
)
...
...
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