我试图在Windows上运行我的代码,但我一直得到这个错误
它可以在Linux上运行,但不能在Windows上运行,有人知道为什么吗?这里是我的完整代码,顺便说一句,我已经尝试过谷歌搜索,使用人工智能,甚至我自己的(有限的)知识,但我不能想出任何东西,我的目标是尝试一个可以在Linux和Windows上运行的版本,所以我会很感激任何可以在两个操作系统上运行的想法
# -------------------Config------------------
archive_prefix = "output"
output_txt_file = "output.txt"
output_html_file = "index.html"
archive_directory = "./archive" # You may enter a relative path (folder needs to start with ./) or you can use a specific path (C:\folder\folder2\)
# Delete or rename old files based on the value of DeleteOldItems variable
DeleteOldItems = False # If false, old items will be stacked in another location
OutputHTML = True # Output as an HTML file so you can open it in a browser and click on the links
HostHTML = False # If OutputHTML = True and HostHTML = True will host on all IPs on port 8080 (to reach if hosted on a personal computer, you can access using localhost:8080 as a URL in your web browser))
# ----------------End config-----------------
import subprocess
import json
import os
from datetime import datetime
# Get the number of times to loop from user input
num_loops = int(input("How many codes would you like?\n>> "))
index = 0 # Do not change
print("")
if DeleteOldItems:
# Delete old files if they exist
if os.path.exists(output_txt_file):
os.remove(output_txt_file)
if os.path.exists(output_html_file):
os.remove(output_html_file)
else:
# Rename old files with timestamp if they exist
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
if os.path.exists(output_txt_file):
new_txt_file = os.path.join(archive_directory,
f"{archive_prefix}_{timestamp}.txt")
os.makedirs(os.path.dirname(new_txt_file), exist_ok=True)
os.rename(output_txt_file, new_txt_file)
print(f"Old output stored as {archive_prefix}_{timestamp}.txt")
if os.path.exists(output_html_file):
new_html_file = os.path.join(archive_directory,
f"{archive_prefix}_{timestamp}.html")
os.makedirs(os.path.dirname(new_html_file), exist_ok=True)
os.rename(output_html_file, new_html_file)
print(f"Old output stored as {archive_prefix}_{timestamp}.html")
# Initialize an empty list to store tokens
tokens = []
# Loop the specified number of times
for _ in range(num_loops):
# Send the POST request using cURL
curl_command = [
'curl', 'https://api.discord.gx.games/v1/direct-fulfillment', '-H',
'authority: api.discord.gx.games', '-H', 'accept: */*', '-H',
'accept-language: en-US,en;q=0.9', '-H',
'content-type: application/json', '-H', 'origin: https://www.opera.com',
'-H', 'referer: https://www.opera.com/', '-H',
'sec-ch-ua: "Opera GX";v="105", "Chromium";v="119", "Not?A_Brand";v="24"',
'-H', 'sec-ch-ua-mobile: ?0', '-H', 'sec-ch-ua-platform: "Windows"',
'-H', 'sec-fetch-dest: empty', '-H', 'sec-fetch-mode: cors', '-H',
'sec-fetch-site: cross-site', '-H',
'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 OPR/105.0.0.0 (Edition std-1)',
'--data-raw',
'{"partnerUserId":"e518cd9e4d526d3de4aeb6d5e36f012bba82443ef1856a68029191ac8c6d136b"}',
'--compressed'
]
response = subprocess.run(curl_command, capture_output=True, text=True)
# Parse the JSON response
response_json = json.loads(response.stdout)
# Get the token from the JSON response if it exists
token = response_json.get("token")
# Print the token if it exists
if token:
# Append the token to the text file
URL = "https://discord.com/billing/partner-promotions/1180231712274387115" + token
if OutputHTML == False:
with open(output_txt_file, 'a') as f:
f.write(URL + '\n\n')
elif OutputHTML == True:
index += 1
with open(output_html_file, 'a') as f:
f.write(f"{index}. <a href=\"{URL}\">{token}</a><br>\n\n")
# Append the token to the list
tokens.append(token)
print("please check for an output file")
if OutputHTML == True & HostHTML == True:
# Host the HTML file as a web server on IP 0.0.0.0 and port 8080
os.system(f"python -m http.server 8080 --bind 0.0.0.0")
字符串
1条答案
按热度按时间owfi6suc1#
这是因为你在
response.stdout
中得到了空字符串,所以当你有json.loads('')
时,它会抛出一个错误,你需要在用json
加载它之前检查这个response.stdout
不是空字符串。试试这个:
字符串