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