I installed the requests package, but when I start to use it, I got this error :
AttributeError: 'module' object has no attribute 'get'
This my code :
from bs4 import BeautifulSoup
import requests
r = requests.get("http://someSite.com/path")
I checked some solution to this problem, and most of them saying that either there is a mistake with importing the package, or that a file with the name requests.py exist in the current directory, but it's not the case for me.
it's been a while since I got this error, and I stuck with it.
any idea? thanks.
UPDATE
FULL error message
Traceback (most recent call last):
File "parser.py", line 2, in <module>
import requests
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 47, in <module>
from cryptography import x509
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/base.py", line 14, in <module>
from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.py", line 14, in <module>
from cryptography.hazmat.backends.interfaces import RSABackend
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 7, in <module>
import pkg_resources
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 76, in <module>
import parser
File "/home/lichiheb/Desktop/parser.py", line 4, in <module>
r = requests.get("http://t...content-available-to-author-only...s.com/search-results-jobs/?searchId=1483197031.949&action=search&page=1&view=list")
AttributeError: 'module' object has no attribute 'get'
Your file is called parser.py which conflicts with a built-in module name parser.
The error message about requests was a weird and unfortunate coincidence. Just rename your module to something else.
Related
I would like to use the cryptography's module on Windows, I am using version 1.12 and Python 3.10.6, and I have some problems. Actually, when I run my script, I receive the error :
`
Traceback (most recent call last):
File "C:/Users/edoua/Documents/cryptographie.py", line 1, in <module>
from cryptography.fernet import Fernet
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\fernet.py", line 16, in <module>
from cryptography.hazmat.primitives.hmac import HMAC
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\primitives\hmac.py", line 10, in <module>
from cryptography.hazmat.backends.openssl.hmac import _HMACContext
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 6, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 13, in <module>
from cryptography import utils, x509
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\x509\__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\x509\base.py", line 28, in <module>
from cryptography.x509.extensions import (
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\x509\extensions.py", line 25, in <module>
from cryptography.x509.general_name import (
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\x509\general_name.py", line 9, in <module>
from email.utils import parseaddr
File "C:\Users/edoua/Documents\email.py", line 18, in <module>
server.login(email_address, email_password)
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\smtplib.py", line 739, in login
(code, resp) = self.auth(
File "C:\Users\edoua\AppData\Local\Programs\Python\Python310\lib\smtplib.py", line 641, in auth
response = encode_base64(initial_response.encode('ascii'), eol='')
NameError: name 'encode_base64' is not defined
`
It is coming from the smtplib.py file. Also, I precise that the module works perfectly, I can use all the functions of the module base64. So the problem is coming from the word 'encode_base64'. Please help !
I tried to launch my program, and that error occures, I expected that it was going to work.
You have a local module C:\Users/edoua/Documents\email.py that is shadowing the email module from the Python standard library. Rename email.py to something else, or move it to somewhere that isn't on the Python path.
All my code is on github except for the token.py file for obvious reasons.
bot.py file
I have had similar issues in the past and have resolved them by reconstructing some code so I apologize in advance if this is another one of those issues where I missed a capital or something but I have tried all the obvious syntax issues and none of them seemed to work. Atom also didn't show any errors.
Here is the whole error message:
Traceback (most recent call last):
File "C:\Users\james\Documents\botpy\bot.py", line 5, in <module>
import discord
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\__init__.py", line 21, in <module>
import logging
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\tokenize.py", line 34, in <module>
from token import *
File "C:\Users\james\Documents\botpy\token.py", line 2, in <module>
from discord.ext import commands
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\__init__.py", line 13, in <module>
from .bot import Bot, AutoShardedBot, when_mentioned, when_mentioned_or
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 27, in <module>
import asyncio
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\_base.py", line 42, in <module>
LOGGER = logging.getLogger("concurrent.futures")
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely due to a circular import)
Try to rename your file into main.py
I had a similar error just because the filename.
This question already has answers here:
Python AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
(23 answers)
Closed 5 years ago.
I am getting an SSL error using twilio. Anybody have any suggestions?
Error:
Traceback (most recent call last):
File "communication_easy/that_guy/communicate.py", line 4, in <module>
from twilio.rest import Client
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/__init__.py", line 14, in <module>
from twilio.http.http_client import TwilioHttpClient
File "/usr/local/lib/python2.7/dist-packages/twilio/http/http_client.py", line 1, in <module>
from requests import Request, Session, hooks
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 84, in <module>
from urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 118, in <module>
SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
Code:
import random
from twilio.rest import Client
TWILIO_ACCOUNT_SID = "asdfasdfsdfsdf"
TWILIO_AUTH_TOKEN = "asdfasdfasdfasf"
TWILIO_NUMBER = "+5555555"
def send_text(body, target_phone_number):
client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
message = client.messages.create(body=body, from_=TWILIO_NUMBER, to=target_phone_number)
send_text(blah, blah)
According to this github ticket, the problem can be solved by upgrading to pyOpenSSL>=16.2.0
Try:
pip install pyOpenSSL -U
I have a clean install of Python 3.3.2 on Windows 7. I'm trying to import html.parser.HTMLParser, using the example from the documentation: Simple HTML and XHTML parser
But I'm getting the error:
>>> from html.parser import HTMLParser
aee4
gg2
Traceback (most recent call last):
File "htmlang.py", line 1, in <module>
from html.parser import HTMLParser
File "c:\Python33\lib\html\parser.py", line 13, in <module>
import warnings
File "c:\Python33\lib\warnings.py", line 6, in <module>
import linecache
File "c:\Python33\lib\linecache.py", line 10, in <module>
import tokenize
File "c:\Python33\lib\tokenize.py", line 37, in <module>
__all__ = token.__all__ + ["COMMENT", "tokenize", "detect_encoding",
AttributeError: 'module' object has no attribute '__all__'
I have just opened the interpreter and typed the import line. Why it isn't working as expected? Why it is printing the weird "aee4" and "gg2" strings?
Just write "import HTMLParser" and it will work
If I import pgdb just in command line, it works fine.
It was also working fine in Eclipse until recently (with exactly the same Python 2.7.2), but now, when I import pgdb, even in a very simple file (containing just import pgdb), I have this error message:
Traceback (most recent call last):
File ".../src/pgdbtest.py", line 8, in <module>
import pgdb
File "build/bdist.macosx-10.6-x86_64/egg/pgdb.py", line 66, in <module>
File "build/bdist.macosx-10.6-x86_64/egg/_pg.py", line 7, in <module>
File "build/bdist.macosx-10.6-x86_64/egg/_pg.py", line 4, in __bootstrap__
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 908, in resource_filename
self, resource_name
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 1383, in get_resource_filename
self._extract_resource(manager, self._eager_to_zip(name))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pkg_resources.py", line 1401, in _extract_resource
timestamp = time.mktime(date_time)
AttributeError: 'module' object has no attribute 'mktime'
In fact, more generally, I discovered that if I try from time import mktime, I also have error:
from time import mktime
ImportError: cannot import name mktime
OK, stupid mistake: I created a package named "time"...
So I just deleted it and everything is alright now.