1
0
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:
Mike Fährmann 2020-10-15 00:43:26 +02:00
parent 7a0ba370d1
commit 1b1cf01d0d
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 7 additions and 4 deletions

View File

@ -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")

View File

@ -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():