add a general 'generate_csrf_token()' function
This commit is contained in:
@@ -9,10 +9,8 @@
|
|||||||
"""Extractors for https://twitter.com/"""
|
"""Extractors for https://twitter.com/"""
|
||||||
|
|
||||||
from .common import Extractor, Message
|
from .common import Extractor, Message
|
||||||
from .. import text, exception
|
from .. import text, util, exception
|
||||||
from ..cache import cache
|
from ..cache import cache
|
||||||
import hashlib
|
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
BASE_PATTERN = (
|
BASE_PATTERN = (
|
||||||
@@ -446,7 +444,7 @@ class TwitterAPI():
|
|||||||
cookies = self.extractor.session.cookies
|
cookies = self.extractor.session.cookies
|
||||||
|
|
||||||
# CSRF
|
# CSRF
|
||||||
csrf = hashlib.md5(str(time.time()).encode()).hexdigest()
|
csrf = util.generate_csrf_token()
|
||||||
self.headers["x-csrf-token"] = csrf
|
self.headers["x-csrf-token"] = csrf
|
||||||
cookies.set("ct0", csrf, domain=".twitter.com")
|
cookies.set("ct0", csrf, domain=".twitter.com")
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import time
|
|||||||
import shutil
|
import shutil
|
||||||
import string
|
import string
|
||||||
import _string
|
import _string
|
||||||
|
import hashlib
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import datetime
|
import datetime
|
||||||
import operator
|
import operator
|
||||||
@@ -60,6 +61,10 @@ def raises(cls):
|
|||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
|
||||||
|
def generate_csrf_token():
|
||||||
|
return hashlib.md5(str(time.time()).encode()).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def combine_dict(a, b):
|
def combine_dict(a, b):
|
||||||
"""Recursively combine the contents of 'b' into 'a'"""
|
"""Recursively combine the contents of 'b' into 'a'"""
|
||||||
for key, value in b.items():
|
for key, value in b.items():
|
||||||
|
|||||||
Reference in New Issue
Block a user