python-requests

Python message.content discord bot

隐身守侯 提交于 2021-02-10 18:43:50
问题 I would like a help, I am trying to make my bot in discord to respond automatically when someone writes some word, the problem is that the command only works if the word is the first thing to be written in the sentence. I wish my bot could respond to the message even when the word is in the middle of some sentence. What should I do? 回答1: Bot = commands.Bot(command_prefix="") @Bot.event async def on_message(message): if "not" in message.content: await Bot.send_message(message.channel, 'yes')

Python message.content discord bot

大憨熊 提交于 2021-02-10 18:41:53
问题 I would like a help, I am trying to make my bot in discord to respond automatically when someone writes some word, the problem is that the command only works if the word is the first thing to be written in the sentence. I wish my bot could respond to the message even when the word is in the middle of some sentence. What should I do? 回答1: Bot = commands.Bot(command_prefix="") @Bot.event async def on_message(message): if "not" in message.content: await Bot.send_message(message.channel, 'yes')

Unable to make python requests over tor ConnectionRefusedError: [WinError 10061]

廉价感情. 提交于 2021-02-10 18:39:57
问题 I am trying to make requests using python requests over tor, but i get the error "ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it". Here is the code i am using: import requests def get_tor_session(): session = requests.session() # Tor uses the 9050 port as the default socks port session.proxies = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'} return session # Make a request through the Tor connection

Unable to make python requests over tor ConnectionRefusedError: [WinError 10061]

五迷三道 提交于 2021-02-10 18:33:10
问题 I am trying to make requests using python requests over tor, but i get the error "ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it". Here is the code i am using: import requests def get_tor_session(): session = requests.session() # Tor uses the 9050 port as the default socks port session.proxies = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'} return session # Make a request through the Tor connection

requests library: Failed to establish a new connection: [Errno 13] Permission denied

不羁的心 提交于 2021-02-10 17:28:13
问题 I have a python script which uses requests library to connect to a device with its web-interface. It uses a url with https connection. sess = requests.Session() try: resp = sess.post('https://' + device + '/url_admin/login.cgi', data=login_data, verify=False) except Exception as e: template = "Exception: {0}\nArguments: {1!r}" print(template.format(type(e).__name__, e.args)) When I try to execute it from command line it works perfectly (even with apache user). However, when it is triggered

Google Cloud Authorized HTTP requests in Python

被刻印的时光 ゝ 提交于 2021-02-10 14:30:46
问题 I am trying to make an authorized request to a Google Cloud function from within Python using this code: import google.auth from google.auth.transport.urllib3 import AuthorizedHttp credentials, project = google.auth.default() authed_http = AuthorizedHttp(credentials) url = "MY_CLOUD_FUNCTON_URL" response = authed_http.request('POST', url) but I am getting the following error: google.auth.exceptions.RefreshError: ('invalid_scope: Invalid OAuth scope or ID token audience provided.', '{"error":

Google Cloud Authorized HTTP requests in Python

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-10 14:29:36
问题 I am trying to make an authorized request to a Google Cloud function from within Python using this code: import google.auth from google.auth.transport.urllib3 import AuthorizedHttp credentials, project = google.auth.default() authed_http = AuthorizedHttp(credentials) url = "MY_CLOUD_FUNCTON_URL" response = authed_http.request('POST', url) but I am getting the following error: google.auth.exceptions.RefreshError: ('invalid_scope: Invalid OAuth scope or ID token audience provided.', '{"error":

How to use requests library without system-configured proxies

人盡茶涼 提交于 2021-02-10 14:28:15
问题 If I supply None or an empty dict to the proxies parameter, requests will automatically fall back to the proxies configured for the operating system as obtained through urllib.request.getproxies() (Python 3) / urllib.getproxies() . import requests r = requests.get('http://google.com', proxies = {}) # or = None... print(r.text) Specifying proxies = { 'http': False } will even cause requests to hang completely for whatever weird reason. So how do I direct requests to perform HTTP requests

How to use requests library without system-configured proxies

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-10 14:27:27
问题 If I supply None or an empty dict to the proxies parameter, requests will automatically fall back to the proxies configured for the operating system as obtained through urllib.request.getproxies() (Python 3) / urllib.getproxies() . import requests r = requests.get('http://google.com', proxies = {}) # or = None... print(r.text) Specifying proxies = { 'http': False } will even cause requests to hang completely for whatever weird reason. So how do I direct requests to perform HTTP requests

How to get JSON data from a Python POST request

泪湿孤枕 提交于 2021-02-10 03:54:28
问题 Whenever I try to get the answer of that POST request command, it returns only the first argument: s = requests.post('https://martindarc59.typeform.com/app/form/result/token/AdHdvM/default') print (s.text) It should output this : enter image description here However, I only get the token value and not the landed_at , I need both in my code to submit them at the end of my form. Thank you ! 回答1: You need to send the "Accept": "application/json" header, i.e.: import requests u = "https:/