bot.run('TOKEN') stopped working - discord.py - discord.py

been using discord.py for well over 6 months and this is the first time I've encountered this error.
This is my code (removed irrelevant commands, still gives this issue):
import discord
import asyncio
from discord import Member
from discord.ext import commands, tasks
from discord.utils import get
import random
import os
import shutil
from itertools import cycle
import keep_alive
bot = commands.Bot(command_prefix=".")
bot.remove_command('help')
#bot.event
async def on_ready():
change_status.start()
print("\nLogged in as: " + bot.user.name + "\n")
bot.run('TOKEN')
keep_alive.keep_alive()
For context, I'm hosting it on replit.com and it's been working fine till it gave me this error earlier today. I have updated discord.py rewrite to the latest version and tried uninstalling/re-installing.
Traceback (most recent call last):
File "main.py", line 86, in <module>
bot.run('TOKEN REMOVED FOR SECURITY REASONS')
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 723, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 216, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 429 Too Many Requests (error code: 0): <!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<title>Access denied | discord.com used Cloudflare to restrict access</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/main.css" type="text/css" media="screen,projection" />
</head>
<body>
<div id="cf-wrapper">
<div class="cf-alert cf-alert-error cf-cookie-error hidden" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>
<div id="cf-error-details" class="p-0">
<header class="mx-auto pt-10 lg:pt-6 lg:px-8 w-240 lg:w-full mb-15 antialiased">
<h1 class="inline-block md:block mr-2 md:mb-2 font-light text-60 md:text-3xl text-black-dark leading-tight">
<span data-translate="error">Error</span>
<span>1015</span>
</h1>
<span class="inline-block md:block heading-ray-id font-mono text-15 lg:text-sm lg:leading-relaxed">Ray ID: 645f3fa78c7d60f8 •</span>
<span class="inline-block md:block heading-ray-id font-mono text-15 lg:text-sm lg:leading-relaxed">2021-04-26 10:50:10 UTC</span>
<h2 class="text-gray-600 leading-1.3 text-3xl lg:text-2xl font-light">You are being rate limited</h2>
</header>
<section class="w-240 lg:w-full mx-auto mb-8 lg:px-8">
<div id="what-happened-section" class="w-1/2 md:w-full">
<h2 class="text-3xl leading-tight font-normal mb-4 text-blac
Traceback (most recent call last):
File "main.py", line 24, in <module>
bot.run('REMOVED TOKEN')
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 723, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 702, in runner
await self.start(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 665, in start
await self.login(*args, bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/#me'))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 216, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 429 Too Many Requests (error code: 0): <!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<title>Access denied | discord.com used Cloudflare to restrict access</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/main.css" type="text/css" media="screen,projection" />
</head>
<body>
<div id="cf-wrapper">
<div class="cf-alert cf-alert-error cf-cookie-error hidden" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>
<div id="cf-error-details" class="p-0">
<header class="mx-auto pt-10 lg:pt-6 lg:px-8 w-240 lg:w-full mb-15 antialiased">
<h1 class="inline-block md:block mr-2 md:mb-2 font-light text-60 md:text-3xl text-black-dark leading-tight">
<span data-translate="error">Error</span>
<span>1015</span>
</h1>
<span class="inline-block md:block heading-ray-id font-mono text-15 lg:text-sm lg:leading-relaxed">Ray ID: 645f462bde228522 •</span>
<span class="inline-block md:block heading-ray-id font-mono text-15 lg:text-sm lg:leading-relaxed">2021-04-26 10:54:37 UTC</span>
<h2 class="text-gray-600 leading-1.3 text-3xl lg:text-2xl font-light">You are being rate limited</h2>
</header>
<section class="w-240 lg:w-full mx-auto mb-8 lg:px-8">
<div id="what-happened-section" class="w-1/2 md:w-full">
<h2 class="text-3xl leading-tight font-normal mb-4 text-black-dark antialiased" data-translate="what_happened">What happened?</h2>
<p>The owner of this website (discord.com) has banned you temporarily from accessing this website.</p>
</div>
</section>
<div class="cf-error-footer cf-wrapper w-240 lg:w-full py-10 sm:py-4 sm:px-8 mx-auto text-center sm:text-left border-solid border-0 border-t border-gray-300">
<p class="text-13">
<span class="cf-footer-item sm:block sm:mb-1">Cloudflare Ray ID: <strong class="font-semibold">645f462bde228522</strong></span>
<span class="cf-footer-separator sm:hidden">•</span>
<span class="cf-footer-item sm:block sm:mb-1"><span>Your IP</span>: 35.232.178.248</span>
<span class="cf-footer-separator sm:hidden">•</span>
<span class="cf-footer-item sm:block sm:mb-1"><span>Performance & security by</span> <a rel="noopener noreferrer" href="https://www.cloudflare.com/5xx-error-landing" id="brand_link" target="_blank">Cloudflare</a></span>
</p>
</div><!-- /.error-footer -->
</div><!-- /#cf-error-details -->
</div><!-- /#cf-wrapper -->
<script type="text/javascript">
window._cf_translation = {};
</script>
</body>
</html>

Inside your error, there is this line
discord.errors.HTTPException: 429 Too Many Requests (error code: 0)
also this
The owner of this website (discord.com) has banned you temporarily from accessing this website.
To fix this problem, just don't host the bot at replit, since there are too many people also trying to host their bots using it, and it has exceeded the limit.

The Error Because You Put The Keep Alive Command Under The Client Run, Also You Imported Keep Alive as Module But Its A Part Of Module.
So Try this:
import discord
import asyncio
from discord import Member
from discord.ext import commands, tasks
from discord.utils import get
import random
import os
import shutil
from itertools import cycle
from webserver import keep_alive
bot = commands.Bot(command_prefix=".")
bot.remove_command('help')
#bot.event
async def on_ready():
change_status.start()
print("\nLogged in as: " + bot.user.name + "\n")
keep_alive()
bot.run('TOKEN')
And Your requirements.txt File Should Be Like This:
discord.py
flask
python-dotenv
And The webserver.py File Should be like this:
from flask import Flask
from threading import Thread
app = Flask('')
#app.route('/')
def home():
return "webserver OK, Discord Bot OK"
def run():
app.run(host="0.0.0.0",port=8080)
def keep_alive():
t = Thread(target=run)
t.start()

bot.run("anime") will block your keep_alive script so that's why you can't make it online forever so make sure you don't have anything bottom of bot.run("token") :)
Happy coding!

Related

How to pickup file contents from HTML file input and hand off to API

I can successfully send image data to an API endpoint with pyscript (1). I can also set up a form and pickup the binary data from a file. I want to put these together so that I pick up the image data and send it to the API in one call. They both use asyncio.ensure_future but I'm not sure how to combine these two processes (getting file data and posting file data to an API). Is there a way to combine these two processes with a single call to asyncio.ensure_future?
(1) send image data to API endpoint
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>GET, POST, PUT, DELETE example</title>
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<py-config>
[[fetch]]
files = ["/request.py"]
</py-config>
</head>
<body><p>
Hello world request example! <br>
Here is the output of your request:
</p>
<py-script>
import asyncio
import json
from request import request # import our request function.
async def main():
baseurl = "https://jsonplaceholder.typicode.com"
# CLD
file = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII="
body = json.dumps({"upload_preset":"<preset>","file":file})
cldheaders={"Content-type": "application/json"}
cldurl = "https://api.cloudinary.com/v1_1/<cloudname>/upload"
new_post = await request(cldurl, body=body, method="POST", headers=cldheaders)
print(f"CLD request=> status:{new_post.status}, json:{await new_post.json()}")
asyncio.ensure_future(main())
</py-script>
<div>
<p>
You can also use other methods. See fetch documentation: <br>
https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters
</p>
</div>
<div>
<p>
See pyodide documentation for what to do with a FetchResponse object: <br>
https://pyodide.org/en/stable/usage/api/python-api.html#pyodide.http.FetchResponse
</p>
</div>
</body>
</html>
(2) process file from a form file input
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<title>File Example</title>
<py-config>
[[fetch]]
files = ["/request.py"]
</py-config>
</head>
<body>
<p>This example shows how to read a file from the local file system and display its contents</p>
<br />
<p>Warning: Not every file type will display. PyScript removes content with tags such as XML, HTML, PHP, etc. Normal
text files will work.</p>
<br />
<p>No content type checking is performed to detect images, executables, etc.</p>
<br />
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
<br />
<br />
<div id="print_output"></div>
<br />
<p>File Content:</p>
<div style="border:2px inset #AAA;cursor:text;height:120px;overflow:auto;width:600px; resize:both">
<div id="content">
</div>
</div>
<py-script output="print_output">
import asyncio
from request import request # import our request function.
import json
from js import document, FileReader, console
from pyodide import create_proxy
from pyodide.http import pyfetch, FetchResponse
from typing import Optional, Any
async def process_file(event):
#print(event.target.files[0].name)
fileList = event.target.files.to_py()
for f in fileList:
#console.log(json.dumps(json.loads(f),indent=2))
#console.log(type(f))
data = await f.text()
console.log("name",f.name)
document.getElementById("content").innerHTML = data
async def main():
# Create a Python proxy for the callback function
# process_file() is your function to process events from FileReader
file_event = create_proxy(process_file)
# Set the listener to the callback
e = document.getElementById("myfile")
#console.log("value of e",e.name)
e.addEventListener("change", file_event, False)
asyncio.ensure_future(main())
</py-script>
</body>
sharing two scripts that show what I've done

i have used laravel blade template make layout but doent work

Template:
<!DOCTYPE html>
<html>
<head>
<title>App Name #yield('title')</title>
</head>
<body>
#section('content')
</div>
</body>
</html>
View:
#section('content')
#if(session('message'))
<p>{{session('message')}}</p>
#endif
#foreach ($posts as $post)
<h2> {{$post->title}}</h2>
<p>{{$post->body}}</p>
Edit
Delete
#endforeach
#endsection
I have used this code and get white screen how to solve this problem
make layout folder and layout file get only white screen no any error and output
MASTE PAGE:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<meta name="csrf-token" content="{{csrf_token()}}">
#yield('metas')
#yield('head')
#yield('style')
</head>
<title>#yield('title')</title>
<body class="skin-blue sidebar-mini">
#yield('body')
</body>
<footer>
#yield('footer')
#yield('script_whole')
</footer>
</html>
CHILD PAGES:
#extends('path.to.master_page')
#section('head')
//head elemetns here
#endsection
#section('style')
//style here
#endsection
#section('title', 'my_title')
#section('content')
//content elemetns here
#endsection
#section('footer')
//footer elemetns here
#endsection
#section('script_whole')
//scripts here
#endsection
and now every page that extends from MASTER_page, so should use #section
Instead of using
#section('content');
in main blade file use
#yield('content');

Thymeleaf PDF template parsing error when using fragment

I'm trying to include a letter head in my PDF templates like so:
fragments/header.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Header</title>
</head>
<body>
<div id="header" class="clearfix" th:fragement="header(sender, name, address1, address2, today)">
<div id="header-left">
<img class="logo" src="app/src/main/resources/template/pdf/assets/logo.png"/>
<div id="recipient">
<p th:object="${sender}"><span th:text="*{name}"></span> - <span th:text="*{address1short}"></span> - <span th:text="*{address2}"></span></p>
<p th:text="${name}"></p>
<p>
<span th:text="${address1}"></span><br/>
<span th:text="${address2}"></span>
</p>
</div>
</div>
<div id="header-right" th:object="${sender}">
<p><strong th:text="*{name}"></strong></p>
<p>
<span th:text="*{address1}"></span><br />
<span th:text="*{address2}"></span><br />
<span class="label" th:text="*{phoneLabel} + ':'"></span><span th:text="*{phone}"></span><br />
<span class="label" th:text="*{faxLabel} + ':'"></span><span th:text="*{fax}"></span><br />
<span class="label" th:text="*{emailLabel} + ':'"></span><span th:text="*{email}"></span><br />
<strong><span th:text="*{internetLabel}"></span>: <span th:text="*{internet}"></span></strong>
</p>
<p>
<span th:text="*{court}"></span><br />
<span th:text="*{registryNr}"></span><br />
<span th:text="*{directorLabel}"></span>: <span th:text="*{director}"></span><br />
<span th:text="*{vatId}"></span><br />
</p>
<p><span th:text="*{todayPrefix}"></span> <span th:text="${today}"></span></p>
</div>
</div>
</body>
</html>
template.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Template</title>
<link rel="stylesheet" type="text/css" media="all" href="app/src/main/resources/template/pdf/assets/style.css"/>
</head>
<body>
<div th:replace="app/src/main/resources/template/pdf/fragments/header :: header(${sender}, ${name}, ${address1}, ${address2}, ${today})"></div>
<!-- omitted for brevity -->
</body>
</html>
Everything works fine when I put the header code in the template directly. But when I try to inlude it as a fragment, like above, I get the following Error:
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "app/src/main/resources/template/pdf/fragments/header.html" - line 9, col 6)
template.html is in the app/src/main/resources/template/pdf/ folder. I had to include css and image files with the full path (from the root of the project) to get them to work. I tried including the fragment with the full path (as above) and only fragements/header, but I get the same error each time.
Im using
spring-boot-starter-thymeleaf 2.1.1
thymeleaf 3.0.11
Stacktrace:
[removed bc of character limit]
UPDATE
The correct path for the fragment is (in my case) "template/pfd/fragment/header" (so, full path from resources folder). Also, there was a typo in th:fragement="header".
The fragment reference should not be absolute to your project, but relative to your thymeleaf template root. So instead of (assuming it is app/src/main/resources/template/ whre your thymeleaf templates are located)
th:replace="app/src/main/resources/template/pdf/fragments/header ..."
use
th:replace="pdf/fragments/header ..."
The common use is
<div th:replace="fragments/header :: header"><div>
Using Thymeleaf

React bootstrap does not work

I have trouble using bootstrap in reactJS. I installed bootstrap using npm, and included the bootstrap css in public.html, but I can only get a button without any style.
public.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap-theme.min.css">
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script src="/js/bundle.js"></script>
</body>
</html>
APP.js:
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import{Button} from 'react-bootstrap';
class App extends Component {
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<button bsSize="large" bsStyle="danger">Test</button>
</div>
);
}
}
export default App;
I appreciate your ideas!
Try changing
<button bsSize="large" bsStyle="danger">Test</button>
to
<button type="button" class="btn btn-danger">Test</button>
Reference: http://getbootstrap.com/css/#buttons
As an aside, I noticed you have both installed and linked a local copy of bootstrap, as well as from CDN. The CDN version shows last, so that will take precedence.

Html Agility Pack, couldn't SelectNodes

Here's the HTML file, it's truncated due to the content size and contained with an "img" tag at the end.
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="utf-8"></meta>
<title>The Waste Land</title>
<link rel="stylesheet" type="text/css" href="wasteland.css" class="day" title="day"/>
<link rel="alternate stylesheet" type="text/css" href="wasteland-night.css" class="night" title="night"/>
</head>
<body>
<section epub:type="frontmatter" id="frontmatter">
<section epub:type="titlepage" id="titlepage">
<h1>The Waste Land</h1>
<div class="aut">T.S. Eliot</div>
<div epub:type="epigraph">
</div>
<p epub:type="dedication">For Ezra Pound: <span xml:lang="it">il migliorfabbro</span></p>
</section>
</section>
<section epub:type="bodymatter" id="bodymatter">
<section id="ch1">
<h2>I. THE BURIAL OF THE DEAD</h2>
<div>Looking into the heart of light, the silence.</div>
<div xml:lang="de" id="ln42">
<em>Od' und leer das Meer</em>.<a epub:type="noteref" class="noteref" href="#note-4">*</a>
</div>
</div>
<div class="linegroup">
<img src="www.href">The lady of situations.
</img>
<div>Here is the man with three staves, and here the Wheel,</div>
<div>And here is the one-eyed merchant, and this card,</div>
</div>
</section>
</body>
Here's my code
HtmlNodeCollection imgNodes= HTMLDoc.DocumentNode.SelectNodes("//img");
or
List<HtmlNode> imgNodes = HTMLDoc.DocumentNode.Descendants().Where(n => n.Name =="img").ToList();
Neither can retrieve any tags. What can i do?

Resources