Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
f6668b6d
authored
Jul 27, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notify: send csrftoken in POST (accept())
parent
f82c9a94
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
notify.py
+12
-4
No files found.
notify.py
View file @
f6668b6d
...
...
@@ -5,6 +5,8 @@
# Notify user about vm expiring
##
import
cookielib
import
errno
import
json
import
logging
import
os
...
...
@@ -53,12 +55,18 @@ def accept():
# Load the saved url
url
=
json
.
load
(
open
(
file_path
,
"r"
))
# Fake data to post so we make urllib2 send a POST instead of a GET
# do POST request to
req
=
urllib2
.
Request
(
url
,
""
,
{
"http_accept"
:
"application/json"
})
cj
=
cookielib
.
CookieJar
()
opener
=
urllib2
.
build_opener
(
urllib2
.
HTTPCookieProcessor
(
cj
))
try
:
rsp
=
urllib2
.
urlopen
(
req
)
opener
.
open
(
url
)
# GET to collect cookies
cookies
=
cj
.
_cookies_for_request
(
urllib2
.
Request
(
url
))
token
=
[
c
for
c
in
cookies
if
c
.
name
==
"csrftoken"
][
0
]
.
value
req
=
urllib2
.
Request
(
url
,
""
,
{
"accept"
:
"application/json"
,
"referer"
:
url
,
"x-csrftoken"
:
token
})
# "content-type": "application/x-www-form-urlencoded"})
rsp
=
opener
.
open
(
req
)
data
=
json
.
load
(
rsp
)
newtime
=
data
[
"new_suspend_time"
]
except
:
...
...
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