New to programming and followed this course: https://www.youtube.com/watch?v=4F2m91eKmts&feature=emb_logo
When things went to Webscraping, got errors:
Code says:
import requests
from bs4 import BeautifulSoup
page = requests.get('https://forecast.weather.gov/MapClick.php?lat=34.05349000000007&lon=-118.24531999999999')
soup = BeautifulSoup(page.content, 'html.parser')
print(soup.find_all('a'))
Return is:
File "/Users/.../python/cleverprogrammer/webscraping.py", line 1, in
import requests File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/init.py",
line 112, in
from . import utils File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/utils.py",
line 26, in
from ._internal_utils import to_native_string File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/_internal_utils.py",
line 11, in
from .compat import is_py2, builtin_str, str File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/compat.py",
line 59, in
from http import cookiejar as cookielib File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/cookiejar.py",
line 39, in
from calendar import timegm ImportError: cannot import name 'timegm' from 'calendar'
(/Users/.../python/cleverprogrammer/calendar.py)
Is there some problem with the way Requests are installed? Maybe use of pipenv is not the correct way?
And why does it call for calendar.py file and 'timegm'? Calendar.py is different file from the same course, in same folder.
What are the steps, that I can take, to get rid of these messages and get working Requests?
Thanks in advance.
Related
I was trying to run some python code in docker and export a .csv file to S3, but got the same error as in aiobotocore - ImportError: cannot import name 'InvalidIMDSEndpointError' (asking here because I don't have enough reputation to comment under that thread..)
File "/opt/conda/lib/python3.7/site-packages/s3fs/__init__.py", line 1, in <module>
from .core import S3FileSystem, S3File
File "/opt/conda/lib/python3.7/site-packages/s3fs/core.py", line 14, in <module>
import aiobotocore
File "/opt/conda/lib/python3.7/site-packages/aiobotocore/__init__.py", line 1, in <module>
from .session import get_session, AioSession
File "/opt/conda/lib/python3.7/site-packages/aiobotocore/session.py", line 6, in <module>
from .client import AioClientCreator, AioBaseClient
File "/opt/conda/lib/python3.7/site-packages/aiobotocore/client.py", line 12, in <module>
from .utils import AioS3RegionRedirector
File "/opt/conda/lib/python3.7/site-packages/aiobotocore/utils.py", line 10, in <module>
from botocore.exceptions import (
ImportError: cannot import name 'InvalidIMDSEndpointError' from 'botocore.exceptions' (/opt/conda/lib/python3.7/site-packages/botocore/exceptions.py)
I tried to use the versions of libraries as in the comment:
botocore==1.19.52
s3fs==0.5.1
boto3==1.16.52
aiobotocore==1.2.0
However, these don't solve the problem and I still get the same error.
Could anyone here give me some hints how to solve this?
Thanks!
Ok, I can answer my own question :)
Just install s3fs, and it will take care of version dependencies of other libraries..
I ran the following code to download an image using urllib module. But I ended up facing some errors as below.
import urllib.request
import random
def downloader(image_url):
file_name = random.randrange(1,10000)
full_file_name = str(file_name) + '.jpg'
urllib.request.urlretrieve(image_url, full_file_name)
url = input("URL ")
downloader(url)
Error Message:
File "img_down.py", line 1, in
import urllib.request File "C:\Users\shekh\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py",
line 88, in
import http.client File "C:\Users\shekh\AppData\Local\Programs\Python\Python36-32\lib\http\client.py",
line 71, in
import email.parser File "C:\Users\shekh\AppData\Local\Programs\Python\Python36-32\lib\email\parser.py",
line 12, in
from email.feedparser import FeedParser, BytesFeedParser File "C:\Users\shekh\AppData\Local\Programs\Python\Python36-32\lib\email\feedparser.py",
line 27, in
from email._policybase import compat32 File "C:\Users\shekh\AppData\Local\Programs\Python\Python36-32\lib\email_policybase.py",
line 7, in
from email import header File "C:\Users\shekh\AppData\Local\Programs\Python\Python36-32\lib\email\header.py",
line 16, in
import email.quoprimime File "C:\Users\shekh\AppData\Local\Programs\Python\Python36-32\lib\email\quoprimime.py",
line 44, in
from string import ascii_letters, digits, hexdigits ImportError: cannot import name 'ascii_letters'
there should be file named string.py in your current directory, renaming it should fix the problem.
From the docs:
When a module named spam is imported, the interpreter searches for a
file named spam.py in the current directory, and then in the list of
directories specified by the environment variable PYTHONPATH. This has
the same syntax as the shell variable PATH, that is, a list of
directory names
so when one of your dependencies try to import string, program first look in the current directory and then in PYTHONPATH
When I simply just import pyfolio, I found this error. I've searched on internet, I found some posts saying it's the API issue BTW data provider and pandas(never able to get yahoo data anyway). However, I couldn't find a way to solve it. Is there anyone can help me with this please?
Thanks a lot for your time.
My version of pandas and pyfolio is below:
pyfolio(0.8.0)
pandas(0.20.3)
pandas-datareader(0.3.0.post0)
import pyfolio
Traceback (most recent call last):
File "", line 1, in
import pyfolio
File "C:\Users\user\Anaconda3\lib\site-packages\pyfolio__init__.py", line 3, in
from . import utils
File "C:\Users\user\Anaconda3\lib\site-packages\pyfolio\utils.py", line 24, in
import empyrical.utils
File "C:\Users\user\Anaconda3\lib\site-packages\empyrical__init__.py", line 21, in
from .stats import (
File "C:\Users\user\Anaconda3\lib\site-packages\empyrical\stats.py", line 23, in
from .utils import nanmean, nanstd, nanmin, up, down, roll, rolling_window
File "C:\Users\user\Anaconda3\lib\site-packages\empyrical\utils.py", line 26, in
from pandas_datareader import data as web
File "C:\Users\user\Anaconda3\lib\site-packages\pandas_datareader__init__.py", line 3, in
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma, # noqa
File "C:\Users\user\Anaconda3\lib\site-packages\pandas_datareader\data.py", line 7, in
from pandas_datareader.google.daily import GoogleDailyReader
File "C:\Users\user\Anaconda3\lib\site-packages\pandas_datareader\google\daily.py", line 1, in
from pandas_datareader.base import _DailyBaseReader
File "C:\Users\user\Anaconda3\lib\site-packages\pandas_datareader\base.py", line 13, in
from pandas_datareader._utils import (RemoteDataError, SymbolWarning,
File "C:\Users\user\Anaconda3\lib\site-packages\pandas_datareader_utils.py", line 5, in
from pandas.core.common import PandasError
ImportError: cannot import name 'PandasError'
Seems to be issue with PyFolio release.
Look at similar issue at GitHub.
Install latest version from clone of GitHub
repository , that should solve the issue otherwise you need to open a issue at GitHub.
There are similar issues about Yahoo URL failures on the site.
You seem to have old version of pandas-datareader latest version is 0.6.0 as of today. And please see that Yahoo API has been deprecated lately
Warning
As of v0.6.0 Yahoo!, Google Options, Google Quotes and EDGAR have been
immediately deprecated due to large changes in their API and no stable
replacement.
On loading httplib in terminal returns no error, but when I load the library in a script, I got this error:
File "test2.py", line 1, in <module>
import httplib
File "/usr/lib/python2.7/httplib.py", line 74, in <module>
from urlparse import urlsplit
File "/home/nakisa/Desktop/testURL/urlparse.py", line 2, in <module>
from tld import get_tld
File "/home/nakisa/Desktop/testURL/src/tld/src/tld/__init__.py",
line 9, in <module>
from tld.utils import get_tld, get_tld_names, update_tld_names, Result
File "/home/nakisa/Desktop/testURL/src/tld/src/tld/utils.py", line
13, in <module>
from six.moves.urllib.parse import urlparse
ImportError: cannot import name urlparse
Does anybody have any suggestion?
You have a file
/home/nakisa/Desktop/testURL/urlparse.py
which is shadowing the built-in Python library urlparse that is required by httplib.
Rename your file.
Edit:
This is what is happening on your machine.
$ cat so.py
import httplib
$ cat urlparse.py
# this is empty
$ python2.7 so.py
Traceback (most recent call last):
File "so.py", line 1, in <module>
import httplib
File "/usr/lib/python2.7/httplib.py", line 74, in <module>
from urlparse import urlsplit
ImportError: cannot import name urlsplit
Edit 2:
Rename your file urlparse.py to something else like myurlparse.py. Then you can import httplib.
Copying the import lines from tap.py...
tap.py:
import site
import user
from site import security, agent
from site.security import models
When I run this i am getting:
File "/home/vikasadmin/user/tap.py", line 31, in init
from site import security, agent
File "/usr/lib/python2.6/site-packages/site/security.py", line 9, in <module>
from site import models
File "/usr/lib/python2.6/site-packages/site/models.py", line 12, in <module>
from site import config
ImportError: cannot import name config
Since I already imported models from site.security this config should have been included. Please explain? How can I solve this?