Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError #12

Open
jokertp opened this issue Jul 19, 2023 · 9 comments
Open

KeyError #12

jokertp opened this issue Jul 19, 2023 · 9 comments

Comments

@jokertp
Copy link

jokertp commented Jul 19, 2023

UploadTest.py
VVV
`from TiktokUploader import uploadVideo

session_id = "my session id"
file = "video_output.mp4"
title = "My Video"
tags = ["fyp", "viral"]

uploadVideo(session_id, file, title, tags, verbose=True)`

Error:

File "TiktokUploader.py", line 200, in uploadVideo x_crsf_toke = r.headers["X-Ware-Csrf-Token"].split(',')[1] File ".local/lib/python3.7/site-packages/requests/structures.py", line 52, in __getitem__ return self._store[key.lower()][1] KeyError: 'x-ware'csrf-token'

All other errors I've had have been because of connection timeouts, but I have yet to try to fix those.

@thiago28x
Copy link

same here. got this from chatgpt:

The error you're encountering is a KeyError raised at the line x_csrf_token = r.headers["X-Ware-Csrf-Token"].split(',')[1] in the uploadVideo function. This error occurs because the "X-Ware-Csrf-Token" header is not present in the response returned by the TikTok server, and the code is trying to access it.

The "X-Ware-Csrf-Token" header is typically used for CSRF (Cross-Site Request Forgery) protection. If the TikTok server has changed its response structure or if there is an issue with the request or authentication, this header might not be included in the response.

To fix this issue, you can add a check to ensure that the "X-Ware-Csrf-Token" header is present before accessing it. Modify the line as follows:

python
Copy code
x_csrf_token = r.headers.get("X-Ware-Csrf-Token", "").split(',')[1]
By using the get() method of the headers dictionary, you can provide a default value (in this case, an empty string) if the header is not found. This way, if the header is missing, x_csrf_token will be an empty string, and the code will continue to execute without raising a KeyError. However, you should make sure to handle the case when the CSRF token is missing appropriately in your code.

After making this change, try running your code again, and see if the issue is resolved. If there are other issues or errors, further debugging might be necessary to identify and address them.

@KundKMC
Copy link
Contributor

KundKMC commented Aug 18, 2023

I think this is not going to work because the header field seems not to be present anymore. Were you successful on reactivating the script?

@Dwilem
Copy link

Dwilem commented Aug 18, 2023

Just tested this and sadly it is not working.

@Dwilem
Copy link

Dwilem commented Aug 19, 2023

Is there any other fix?

@liyouyoumao
Copy link

	#x_csrf_token = r.headers["X-Ware-Csrf-Token"].split(',')[1]

	params = {
		"video_id":video_id,
		"visibility_type":"0",
		"poster_delay":"0",
		"text":text,
		"text_extra":json.dumps(text_extra),
		"allow_comment":"1",
		"allow_duet":"0",
		"allow_stitch":"0",
		"sound_exemption":"0",
		"aid":"1988",
	}
	if schedule_time:
		params["schedule_time"] = schedule_time
	#headers = {"X-Secsdk-Csrf-Token": x_csrf_token}

You need to remove this line of code

@zat2pil
Copy link

zat2pil commented Aug 22, 2023

	#x_csrf_token = r.headers["X-Ware-Csrf-Token"].split(',')[1]

	params = {
		"video_id":video_id,
		"visibility_type":"0",
		"poster_delay":"0",
		"text":text,
		"text_extra":json.dumps(text_extra),
		"allow_comment":"1",
		"allow_duet":"0",
		"allow_stitch":"0",
		"sound_exemption":"0",
		"aid":"1988",
	}
	if schedule_time:
		params["schedule_time"] = schedule_time
	#headers = {"X-Secsdk-Csrf-Token": x_csrf_token}

You need to remove this line of code

It works, but when file is uploaded to tiktok, then it doesn't has any audio

@zat2pil
Copy link

zat2pil commented Aug 23, 2023

	#x_csrf_token = r.headers["X-Ware-Csrf-Token"].split(',')[1]

	params = {
		"video_id":video_id,
		"visibility_type":"0",
		"poster_delay":"0",
		"text":text,
		"text_extra":json.dumps(text_extra),
		"allow_comment":"1",
		"allow_duet":"0",
		"allow_stitch":"0",
		"sound_exemption":"0",
		"aid":"1988",
	}
	if schedule_time:
		params["schedule_time"] = schedule_time
	#headers = {"X-Secsdk-Csrf-Token": x_csrf_token}

You need to remove this line of code

It works, but when file is uploaded to tiktok, then it doesn't has any audio

In browser it shows that video is uploaded, but without sound, but from other devices you can't see this video

@liyouyoumao
Copy link

	#x_csrf_token = r.headers["X-Ware-Csrf-Token"].split(',')[1]

	params = {
		"video_id":video_id,
		"visibility_type":"0",
		"poster_delay":"0",
		"text":text,
		"text_extra":json.dumps(text_extra),
		"allow_comment":"1",
		"allow_duet":"0",
		"allow_stitch":"0",
		"sound_exemption":"0",
		"aid":"1988",
	}
	if schedule_time:
		params["schedule_time"] = schedule_time
	#headers = {"X-Secsdk-Csrf-Token": x_csrf_token}

You need to remove this line of code

It works, but when file is uploaded to tiktok, then it doesn't has any audio

In browser it shows that video is uploaded, but without sound, but from other devices you can't see this video

I uploaded successfully and it is with sound, I can only log in to tiktok through the browser no other device

@KundKMC
Copy link
Contributor

KundKMC commented Aug 25, 2023

But you didn't add a pull request, here ;( I'm gonna do a retest and then create a pull request. Maybe we get this thing back on track.

KundKMC added a commit to KundKMC/Tiktok-uploader that referenced this issue Aug 25, 2023
MiniGlome added a commit that referenced this issue Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants