Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
6d053b35
Commit
6d053b35
authored
12 years ago
by
Victor Shnayder
Browse files
Options
Downloads
Patches
Plain Diff
change sample upload script to work properly over https
parent
697c1d7b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/lib/sample-post.py
+29
-15
29 additions, 15 deletions
common/lib/sample-post.py
with
29 additions
and
15 deletions
common/lib/sample-post.py
+
29
−
15
View file @
6d053b35
...
...
@@ -2,46 +2,60 @@
import
requests
import
sys
import
getpass
def
prompt
(
msg
,
default
=
None
):
def
prompt
(
msg
,
default
=
None
,
safe
=
False
):
d
=
'
[{0}]
'
.
format
(
default
)
if
default
is
not
None
else
''
print
'
Enter {msg}{default}:
'
.
format
(
msg
=
msg
,
default
=
d
)
x
=
sys
.
stdin
.
readline
().
strip
()
prompt
=
'
Enter {msg}{default}:
'
.
format
(
msg
=
msg
,
default
=
d
)
if
not
safe
:
print
prompt
x
=
sys
.
stdin
.
readline
().
strip
()
else
:
x
=
getpass
.
getpass
(
prompt
=
prompt
)
if
x
==
''
and
default
is
not
None
:
return
default
return
x
# http://127.0.0.1:8000/courses/MITx/7012x/2013_Spring/modx/i4x://MITx/7012x/problem/example_functional_groups/problem_check
server
=
'
https://www.edx.org
'
course_id
=
'
HarvardX/PH207x/2012_Fall
'
location
=
'
i4x://HarvardX/PH207x/problem/ex_practice_2
'
server
=
prompt
(
'
Server (no trailing slash)
'
,
'
http://127.0.0.1:8000
'
)
course_id
=
prompt
(
'
Course id
'
,
'
MITx/7012x/2013_Spring
'
)
location
=
prompt
(
'
problem location
'
,
'
i4x://MITx/7012x/problem/example_upload_answer
'
)
#server = prompt('Server (no trailing slash)', 'http://127.0.0.1:8000')
#course_id = prompt('Course id', 'MITx/7012x/2013_Spring')
#location = prompt('problem location', 'i4x://MITx/7012x/problem/example_upload_answer')
value
=
prompt
(
'
value to upload
'
)
print
"
logging in
"
username
=
prompt
(
'
username on server
'
,
'
victor@edx.org
'
)
password
=
prompt
(
'
password
'
,
'
abc123
'
,
safe
=
True
)
print
"
get csrf cookie
"
session
=
requests
.
session
()
r
=
session
.
get
(
server
+
'
/
'
)
r
.
raise_for_status
()
print
session
.
cookies
# print session.cookies
# for some reason, the server expects a header containing the csrf cookie, not just the
# cookie itself.
session
.
headers
[
'
X-CSRFToken
'
]
=
session
.
cookies
[
'
csrftoken
'
]
# for https, need a referer header
session
.
headers
[
'
Referer
'
]
=
server
+
'
/
'
login_url
=
'
/
'
.
join
([
server
,
'
login
'
])
r
=
session
.
post
(
login_url
,
{
'
email
'
:
'
victor@edx.org
'
,
'
password
'
:
'
abc123
'
})
print
"
request headers:
"
,
r
.
request
.
headers
print
"
response headers:
"
,
r
.
headers
print
"
log in
"
r
=
session
.
post
(
login_url
,
{
'
email
'
:
'
victor@edx.org
'
,
'
password
'
:
'
Secret!
'
,
'
remember
'
:
'
false
'
})
#print "request headers: ", r.request.headers
#print "response headers: ", r.headers
r
.
raise_for_status
()
url
=
'
/
'
.
join
([
server
,
'
courses
'
,
course_id
,
'
modx
'
,
location
,
'
problem_check
'
])
data
=
{
'
input_{0}_2_1
'
.
format
(
location
.
replace
(
'
/
'
,
'
-
'
).
replace
(
'
:
'
,
''
).
replace
(
'
--
'
,
'
-
'
)):
value
}
#data = {'input_i4x-MITx-7012x-problem-example_upload_answer_2_1': value}
print
"
Posting to
'
{0}
'
: {1}
"
.
format
(
url
,
data
)
r
=
session
.
post
(
url
,
data
)
r
.
raise_for_status
()
print
(
"
To see the uploaded answer, go to {server}/courses/{course_id}/jump_to/{location}
"
.
format
(
server
=
server
,
course_id
=
course_id
,
location
=
location
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment