Geopy - ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' - python

When trying to import distance method from geopy.distance I am receiving the below error:
from geopy.distance import distance
File "C:\Users\cnethi\AppData\Local\Continuum\miniconda3\envs\airbnb\lib\site-packages\geopy\__init__.py", line 12, in <module>
from geopy.geocoders import * # noqa
File "C:\Users\cnethi\AppData\Local\Continuum\miniconda3\envs\airbnb\lib\site-packages\geopy\geocoders\__init__.py", line 120, in <module>
from geopy.geocoders.arcgis import ArcGIS
File "C:\Users\cnethi\AppData\Local\Continuum\miniconda3\envs\airbnb\lib\site-packages\geopy\geocoders\arcgis.py", line 5, in <module>
from geopy.compat import Request, string_compare, urlencode
File "C:\Users\cnethi\AppData\Local\Continuum\miniconda3\envs\airbnb\lib\site-packages\geopy\compat.py", line 56, in <module>
from urllib.request import (HTTPBasicAuthHandler, HTTPPasswordMgrWithDefaultRealm,
ImportError: cannot import name 'HTTPSHandler' from 'urllib.request'
Can anyone please help in fixing this issue with 'HTTPSHandler' in 'urllib.request' file?
Python version - Earlier it was 3.5.x. I saw a post saying that updating python would fix it, but it didnot. Current version is 3.7.7. Also, I am using a virtual environment.
Github link for urllib.request - https://github.com/python/cpython/tree/3.8/Lib/urllib/request.py - There is a HTTPSHandler class, but it is inside an if statement.

Related

cannot import name 'Mapping' from 'collections' on importing requests

Python Version: Python 3.10.4
PIP Version: pip 22.0.4
So I was trying to make a small project with sockets, I added a feature to upload files but whenever I import requests, it throws this error. Below is the code I ran.
Traceback (most recent call last):
File "C:\Programming\WireUS\test.py", line 1, in <module>
import requests
File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 29, in <module>
from .connection import (
File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 39, in <module>
from .util.ssl_ import (
File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\__init__.py", line 3, in <module>
from .connection import is_connection_dropped
File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\connection.py", line 3, in <module>
from .wait import wait_for_read
File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\wait.py", line 1, in <module>
from .selectors import (
File "C:\Users\John\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\selectors.py", line 14, in <module>
from collections import namedtuple, Mapping
ImportError: cannot import name 'Mapping' from 'collections' (C:\Users\John\AppData\Local\Programs\Python\Python310\lib\collections\__init__.py)
Even this basic code gives me that error.
import requests
import time
r = request.get("google.com").text
print(r)
time.sleep(999)
As user2357112-supports-monica said, running pip install urllib3 fixes it.
you have to mention the schema (http, ftp,https) of your url :
import requests
import time
r = requests.get("https://google.com").text
print(r)
Just try to edit the selectors.py file
from
from collections import Mapping
to
from collections.abc import Mapping
This is a compatibility issue between different versions of python 3

ImportError: cannot import name 'DocToHtml' from 'robot.libdocpkg.htmlwriter' (C:\Python37\lib\site-packages\robot\libdocpkg\htmlwriter.py)

I see this message after updating the robotframework version form 3.2.2 to 4.1.1
Maybe someone faced a similar issue and has a solution? I suppose it is somehow connected to another problem https://github.com/nokia/RED/issues/413
Here is Traceback:
File "kubeless.py", line 23, in <module>
from robot_hub import RobotHub
File "c:\opt\robot\robot_hub.py", line 9, in <module>
from rfhub import blueprints
File "C:\Python37\lib\site-packages\rfhub\blueprints\__init__.py", line 1, in <module>
from rfhub.blueprints.api import blueprint as api
File "C:\Python37\lib\site-packages\rfhub\blueprints\api\__init__.py", line 9, in <module>
from . import keywords
File "C:\Python37\lib\site-packages\rfhub\blueprints\api\keywords.py", line 7, in <module>
from robot.libdocpkg.htmlwriter import DocToHtml
ImportError: cannot import name 'DocToHtml' from 'robot.libdocpkg.htmlwriter' (C:\Python37\lib\site-packages\robot\libdocpkg\htmlwriter.py)
kubeless.py
...
from robot_hub import RobotHub
...
if __name__ == '__main__':
app.hub = RobotHub(app)
...
I found that package rfhub v 1.0.1 (https://pypi.org/project/robotframework-hub/) doesnt support robotframework version > 4.0. There isnt required method in htmlwriter.py

how to fix 'AttributeError: module 'IPython' has no attribute 'utils'' while imporing my own module

I have made my own class in python, but while making an object it gives strange error "AttributeError: module 'IPython' has no attribute 'utils'". This error is coming from the import statement in the init function in my module. I am importing from moviepy.
I have tried writing the import statement outside the class. I am trying to make an importable package for my personal use.
class video_reader_writer:
def __init__(self,video_file):
from moviepy.editor import ImageSequenceClip // error here
from moviepy.audio.AudioClip import AudioArrayClip
import numpy as np
...
This is the stack trace :
from moviepy.editor import ImageSequenceClip
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\editor.py", line 49, in <module>
from .video.io.html_tools import ipython_display
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\io\html_tools.py", line 20, in <module>
from IPython.display import HTML
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\__init__.py", line 54, in <module>
from .core.application import Application
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\application.py", line 25, in <module>
from IPython.core import release, crashhandler
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
from IPython.core import ultratb
File "C:\Users\sagar\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\ultratb.py", line 128, in <module>
import IPython.utils.colorable as colorable
AttributeError: module 'IPython' has no attribute 'utils'

from requests import Session as OriginalSession ImportError: cannot import name 'Session'

I don't understand the error I get and searching online was not helpful.
Traceback (most recent call last):
File "/Users/<path>/file.py", line 1, in <module>
from coinmarketcap import Market
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/coinmarketcap/__init__.py", line 10, in <module>
from .core import Market
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/coinmarketcap/core.py", line 8, in <module>
import requests_cache
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests_cache/__init__.py", line 28, in <module>
from .core import(
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests_cache/core.py", line 14, in <module>
from requests import Session as OriginalSession
ImportError: cannot import name 'Session'
It seems to be generated from the very first line where the import and code is the following:
from coinmarketcap import Market
cmc = Market()
coins = cmc.ticker(limit=15) # assumes Dash in top 15.
print(coins)
Not sure if it helps but I had similar issue with import - turned out I have created requests.py file and imported stuff from there. It caused namespace clash as other libraries I used in the project were dependent on built-in requests module.

"Import Error: cannot import name 'unicode_literals' "

Sorry if this is a dumb question but I'm trying to import and open a CSV using pandas in Python. Whenever I hit run I get the syntax error "cannot import name 'unicode_literals'". I have no idea why that is happening and I haven't been able to find any source online which details what this error means.
This is my code:
import pandas as pd
with open(r"FILEPATH\File.csv") as rawData:
pd.read_csv(rawData)
Here is the Error:
C:\Anaconda3\python.exe "FILEPATH"
Traceback (most recent call last):
File "FILEPATH/Main.py", line 1, in <module>
import pandas as pd
File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas\src\numpy.pxd", line 157, in init pandas.hashtable (pandas\hashtable.c:22997)
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 107, in <module>
from __future__ import division, absolute_import, print_function
File "C:\Anaconda3\lib\__future__.py", line 23, in <module>
from __future__ import unicode_literals
ImportError: cannot import name 'unicode_literals'
cannot import name 'unicode_literals'
Any suggestions for why this isn't working would be greatly appreciated.
You're on the right track! The only thing you have to do is add another parameter to open(). This would yield:
import pandas as pd
with open(r"FILEPATH\File.csv", encoding='utf-8') as rawData:
pd.read_csv(rawData)

Categories