Requests. __init__() got an unexpected keyword argument 'strict' - python

I need your help.
I get this error using requests.get():
__init__() got an unexpected keyword argument 'strict'
I found only one piece of advice online which is to update the requests library, but it did not change anything.
Python 3.9, Requests 2.27.1.
print(requests.__version__)
2.27.1
Here is a code:
import requests
url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=###########'
r = requests.get(url)
Here is a Traceback
r = requests.get(url)
Traceback (most recent call last):
File "C:\Users\OLEG~1.KAZ\AppData\Local\Temp/ipykernel_13156/3951091591.py", line 1, in <module>
r = requests.get(url)
File "C:\Users\oleg.kazanskyi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\oleg.kazanskyi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\oleg.kazanskyi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 335, in request
File "C:\Users\oleg.kazanskyi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 438, in send
auth = request.auth
File "C:\Users\oleg.kazanskyi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 282, in send
response.url = req.url
File "C:\Users\oleg.kazanskyi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 423, in urlopen
File "C:\Users\oleg.kazanskyi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 238, in _get_conn
File "C:\Users\oleg.kazanskyi\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 560, in _new_conn
TypeError: __init__() got an unexpected keyword argument 'strict'
Does anyone have a fix?

Thank you, #deceze, for the piece of advice.
I removed the XMLA and Requests libraries and reinstalled both as it's described here:
github.com/psf/requests/issues/5959
Now it works.
For whatever reason, I did it twice to make it work.

Related

Why am I getting an error when using the requests module to return the server code?

(I used a translator when writing this article. Please understand that some words may be incorrect.)
I tested it using the requests module. If the site cannot be found, a 404 code should be returned, but with an error. I don't know what the reason is. Any help would be appreciated. How to properly return a 404 code?
---Below is the code.
import requests as re
a = re.get(input())
print(a.status_code)
error :
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 515, in request
prep = self.prepare_request(req)
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 443, in prepare_request
p.prepare(
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 318, in prepare
self.prepare_url(url, params)
File "C:\Users\82104_dvfqr9f\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 392, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'eeee.com': No scheme supplied. Perhaps you meant http://eeee.com?
You can use this link for how to work with requests module.
import requests
try:
r = requests.get('https://www.google.com/search?q=ggg')
print(r.status_code)
if r.status_code==404:
print("this url dosn't exist")
except Exception as error:
print(error)

Best way to use Python and Bit Bucket

I am having problems with Python and Bit Bucket. To display/pull/push do anything really.
I am looking # Two different libs, atlassian-python-api, and stashy, both seem to have problems my code is very simple:
from atlassian import Bitbucket
import getpass
username = input("What is your username: ")
password = getpass.getpass(prompt="Enter your password?: ")
bitbucket = Bitbucket(
url="https://website.com:port/projects/demo_projects/repppos/",
username=username,
password=password)
data = bitbucket.project_list()
both give me this error: using stashy and another library. I heard someone suggest to use Rest API but I have no experience with this?
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/ProjectName/terrafw_gui/test_no_gui.py", line 12, in <module>
data = bitbucket.project_list()
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\atlassian\bitbucket.py", line 22, in project_list
return (self.get('rest/api/1.0/projects', params=params) or {}).get('values')
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\atlassian\rest_client.py", line 208, in get
trailing=trailing)
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\atlassian\rest_client.py", line 151, in request
files=files
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\requests\sessions.py", line 279, in request
resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\requests\sessions.py", line 374, in send
r = adapter.send(request, **kwargs)
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\requests\adapters.py", line 174, in send
timeout=timeout
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 417, in urlopen
conn = self._get_conn(timeout=pool_timeout)
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 232, in _get_conn
return conn or self._new_conn()
File "C:\Users\User\PycharmProjects\ProjectName\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 547, in _new_conn
strict=self.strict)
TypeError: __init__() got an unexpected keyword argument 'strict'
Process finished with exit code 1
I cannot figure out how come, or why I am getting these error messages without an attempted connection (the error is given immediately without any seconds for timeout).

Tried to upvote a reddit submission but received a 404 HTTP response

I'm new to coding and I suck. I hope to find help here.
I was playing around with the praw module for reddit and couldn't get the simple function upvote() to work.
Here's my code:
import praw
r = praw.Reddit(client_id='**************',
client_secret='**************',
user_agent='**************',
username='**************',
password='***********')
r.submission('https://www.reddit.com/r/aww/comments/9znyf2/today_is_my_18th_birthday_everyone/').upvote()
And here's the full error:
Traceback (most recent call last):
File "C:\Users\*****\Desktop\*****\*****\*****\*****\*****\A.py", line 11, in <module>
r.submission('https://www.reddit.com/r/aww/comments/9znyf2/today_is_my_18th_birthday_everyone/').upvote()
File "C:\Users\*****\AppData\Local\Programs\Python\Python37\lib\site-packages\praw\models\reddit\mixins\votable.py", line 80, in upvote
self._vote(direction=1)
File "C:\Users\*****\AppData\Local\Programs\Python\Python37\lib\site-packages\praw\models\reddit\mixins\votable.py", line 10, in _vote
'id': self.fullname})
File "C:\Users*****\AppData\Local\Programs\Python\Python37\lib\site-packages\praw\reddit.py", line 465, in post
params=params)
File "C:\Users\*****\AppData\Local\Programs\Python\Python37\lib\site-packages\praw\reddit.py", line 506, in request
params=params)
File "C:\Users\*****\AppData\Local\Programs\Python\Python37\lib\site-packages\prawcore\sessions.py", line 185, in request
params=params, url=url)
File "C:\Users\*****\AppData\Local\Programs\Python\Python37\lib\site-packages\prawcore\sessions.py", line 130, in _request_with_retries
raise self.STATUS_EXCEPTIONS[response.status_code](response)
prawcore.exceptions.NotFound: received 404 HTTP response
PRAW is trying to use that URL as a post ID, not as a URL. url is the second argument to reddit.submission(), so you'll need to use it as a named argument (r.submission(url='https://www.reddit.com/...')) to get the submission. After you do that everything should work as expected.

How to handle the "Traceback" error in python?

Can anyone please tell me How do I remove this Traceback (most recent call last): Error in python. I am using python 2.7.9
Take a look over the code.
import requests
import optparse
parser = optparse.OptionParser()
parser.add_option("-f", '--filename', action="store" ,dest="filee")
options, args = parser.parse_args()
file = options.filee
fopen = open(file, 'r')
for x in fopen.readlines():
print "Checking for Clickjacking vulnerability\n"
url = x.strip('\n')
req = requests.get(url)
try:
print "[-]Target:" + url + " Not vulnerable\n The targeted victim has %s header\n" % (req.headers['X-Frame-Options'])
except Exception as e:
print "[+] Target:" + url +" Vulnerable to clickjacking"
After running the code successfully I go this error at the end
Traceback (most recent call last):
File "C:\Python27\utkarsh3.py", line 17, in <module>
req = requests.get(url)
File "C:\Python27\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 494, in request
prep = self.prepare_request(req)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 437, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "C:\Python27\lib\site-packages\requests\models.py", line 305, in prepare
self.prepare_url(url, params)
File "C:\Python27\lib\site-packages\requests\models.py", line 379, in prepare_url
raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '': No schema supplied. Perhaps you meant http://?
Which really irritate me. I know there are so many peoples who are already asking this before. But I can't understand it so I ask.
And please tell me How we beginners handle these errors?
in a eli5 fashion, a Traceback is a log of what the program was trying to do before actual error happened. Your actual error is requests.exceptions.MissingSchema
The line that follows Invalid URL '': No schema supplied. Perhaps you meant http://? describes the exact problem.
File "C:\Python27\utkarsh3.py", line 17, in <module>
req = requests.get(url)
These above lines describe where the error started..
So, if you go to line 17 of your program you must see this exact same line.
Making a context out of these two things, i get that url is a string that is just example.com and not http://example.com or something on those lines.
I can only speculate so much on what your code might be. But, feel free to provide your code snippets to explain more.
But, hope this helps you to read future tracebacks.
Edit1 : Now that you added snippet. Try printing url just before requests.get(url) and see what exactly you are trying to reach. And, if you have the right schema prepended.

requests: TypeError: 'tuple' object is not callable in python 3.1.2

I'm making a web page scraper using BeautifulSoup4 and requests libraries. I had some trouble with BeautifulSoup working but got some help and was able to get that fixed. Now I've run into a new problem and I'm not sure how to fix it. I'm using requests 2.2.1 and I'm trying to run this program on Python 3.1.2. And when I do I get a traceback error.
here is my code:
from bs4 import BeautifulSoup
import requests
url = input("Enter a URL (start with www): ")
link = "http://" + url
page = requests.get(link).content
soup = BeautifulSoup(page)
for url in soup.find_all('a'):
print(url.get('href'))
print()
and the error:
Enter a URL (start with www): www.google.com
Traceback (most recent call last):
File "/Users/user/Desktop/project.py", line 8, in <module>
page = requests.get(link).content
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/requests-2.2.1-py3.1.egg/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/requests-2.2.1-py3.1.egg/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/requests-2.2.1-py3.1.egg/requests/sessions.py", line 349, in request
prep = self.prepare_request(req)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/requests-2.2.1-py3.1.egg/requests/sessions.py", line 287, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/requests-2.2.1-py3.1.egg/requests/models.py", line 287, in prepare
self.prepare_url(url,params)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/requests-2.2.1-py3.1.egg/requests/models.py", line 321, in prepare_url
url = str(url)
TypeError: 'tuple' object is not callable
I've done some looking and when others have gotten this error (in django mostly) there was a comma missing but I'm not sure where to put a comma at? Any help will be appreciated.

Categories