ImportError: No module named 'httplib' - python

My code:
from selenium import webdriver
driver= webdriver.Firefox()
driver.get("http://google.com")
getting the following error messages
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/selenium.py", line 23, in <module>
NewjerseyCalifornia
import http.client as http_client
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/client.py", line 71, in <module>
import email.parser
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/feedparser.py", line 27, in <module>
from email import message
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/message.py", line 16, in <module>
from email import utils
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/utils.py", line 40, in <module>
from email.charset import Charset
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/charset.py", line 15, in <module>
import email.quoprimime
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/email/quoprimime.py", line 44, in <module>
from string import ascii_letters, digits, hexdigits
ImportError: cannot import name 'ascii_letters'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/asimali/PycharmProjects/Asim/com/introduction/Basics_Selenium.py", line 4, in <module>
from selenium import webdriver File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/__init__.py", line 18, in <module>
from selenium import selenium File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/selenium.py", line 25, in <module>
import httplib as http_client ImportError: No module named 'httplib' Process finished with exit code 1
Note : I also ran the command 2to3 -w Basics_Selenium.py

Related

ImportError: cannot import name 'total_ordering' from 'functools' error in Pycharm virtual env

All of a sudden i am getting below error while running my code in Pycharm. Earlier It was working fine. I tried changing the interpretar from virtual en to base interpreter but no resolve
Traceback (most recent call last):
File "/Users/ubhatia/PycharmProjects/ModerationReport/resources/user_keywords/keyword.py", line 3, in <module>
from robot.api.deco import library, keyword
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/__init__.py", line 43, in <module>
from robot.rebot import rebot, rebot_cli
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/rebot.py", line 40, in <module>
from robot.conf import RebotSettings
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/conf/__init__.py", line 27, in <module>
from .settings import RobotSettings, RebotSettings
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/conf/settings.py", line 16, in <module>
import glob
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/glob.py", line 4, in <module>
import re
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/re.py", line 127, in <module>
import functools
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/functools.py", line 21, in <module>
from collections import namedtuple
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/collections/__init__.py", line 22, in <module>
from keyword import iskeyword as _iskeyword
File "/Users/ubhatia/PycharmProjects/ModerationReport/resources/user_keywords/keyword.py", line 3, in <module>
from robot.api.deco import library, keyword
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/api/__init__.py", line 71, in <module>
from robot.model import SuiteVisitor
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/model/__init__.py", line 28, in <module>
from .body import BaseBody, Body, BodyItem, Branches
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/model/body.py", line 18, in <module>
from .itemlist import ItemList
File "/Users/ubhatia/.virtualenvs/ModerationReport/lib/python3.7/site-packages/robot/model/itemlist.py", line 17, in <module>
from functools import total_ordering
ImportError: cannot import name 'total_ordering' from 'functools' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/functools.py)
This is the piece of code i am running
import time
from datetime import date, timedelta
from robot.api.deco import library, keyword
from robot.libraries.BuiltIn import BuiltIn
import pandas as pd
def get_current_date():
today = time.strftime('%d/%m/%Y')
return today
def get_yesterday_date():
today = date.today()
yesterday = today - timedelta(days=1)
return yesterday.strftime('%d/%m/%Y')
def read_excel_and_change_to_list(excel_path):
return pd.read_excel(excel_path)
print(get_current_date())
Can anyone help me out on how to resolve this issue please?

ImportError: cannot import name 'urlencode'

try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
import speech_recognition
when I run import speech_recognition normally it gives an error
Traceback (most recent call last):
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\site-packages\speech_recognition\__init__.py", line 29, in <module>
from urllib import urlencode
ImportError: cannot import name 'urlencode'
During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "C:\Users\Vatsa\OneDrive\Desktop\New folder\New folder\virtual ai assistant.py", line 2, in <module>
import speech_recognition as sr
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\site-packages\speech_recognition\__init__.py", line 33, in <module>
from urllib.request import Request, urlopen
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 88, in <module>
import http.client
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\email\utils.py", line 33, in <module>
from email._parseaddr import quote
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\email\_parseaddr.py", line 16, in <module>
import time, calendar
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\calendar.py", line 50, in <module>
class _localized_month:
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\calendar.py", line 52, in _localized_month
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
File "C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\lib\calendar.py", line 52, in <listcomp>
_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)]
AttributeError: module 'datetime' has no attribute 'date'
[Finished in 0.7s with exit code 1]
[shell_cmd: python -u "C:\Users\Vatsa\OneDrive\Desktop\New folder\New folder\virtual ai assistant.py"]
[dir: C:\Users\Vatsa\OneDrive\Desktop\New folder\New folder]
[path: C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Android;C:\Windows\System32;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\Vatsa\AppData\Local\Programs\Python\Python36\;C:\Users\Vatsa\AppData\Local\Microsoft\WindowsApps;C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\bin;C:\Users\Vatsa\AppData\Local\GitHubDesktop\bin;C:\Users\Vatsa\AppData\Local\atom\bin;C:\Users\Vatsa\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Vatsa\.dotnet\tools]
so I checked about this and changed the code as it is at the very top but when I run that I still receive the same error.
Reposting from my comment:
You have a file named datetime.py that's being imported instead of stdlib datetime, just rename the file to something different.

Selenium files error, i'm not able to import them correctly

i have tried everything...stackoverflow is the final option
from selenium import *
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.maximize_window()
location = r"C:\Users\rehma\PycharmProjects\myProject\webpage.html"
driver.get(location)
Clicking on the "Alert" button to generate the Simple Alert
button = driver.find_element_by_name('alert')
button.click()
Switching the control to the Alert window
obj = driver.switch_to.alert
Retrieving the message on the Alert window
msg = obj.text
print("Alert shows following message: "+ msg )
time.sleep(2)
using the accept() method to accept the alert
obj.accept()
print(" Clicked on the OK Button in the Alert Window")
driver.close
Now heres the error
Traceback (most recent call last):
File "C:\Users\rehma\PycharmProjects\myProject\testing.py", line 4, in <module>
from selenium import webdriver
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 29, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 27, in <module>
from .remote_connection import RemoteConnection
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 24, in <module>
import urllib3
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\urllib3\__init__.py", line 7, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\urllib3\packages\six.py", line 199, in load_module
mod = mod._resolve()
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\urllib3\packages\six.py", line 113, in _resolve
return _import_module(self.mod)
File "C:\Users\rehma\PycharmProjects\myProject\venv\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Users\rehma\Downloads\lib\http\client.py", line 71, in <module>
import email.parser
ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package
Your file is probably named email.py, change it to something different.

ImportError: cannot import name 'port_by_scheme' from 'urllib3.connection'

I tried to open Google via selenium but i got this error.Can anyone explain ?
from selenium import webdriver
driver = webdriver.Chrome("C:\\Users\\Dimitar\\Desktop\\chromedriver.exe")
driver.get ("https://www.facebook.com")
Traceback (most recent call last):
File "C:/Users/Dimitar/PycharmProjects/helloworld/new.py", line 1, in <module>
from selenium import webdriver
File "C:\Users\Dimitar\PycharmProjects\helloworld\venv\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "C:\Users\Dimitar\PycharmProjects\helloworld\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 29, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "C:\Users\Dimitar\PycharmProjects\helloworld\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 27, in <module>
from .remote_connection import RemoteConnection
File "C:\Users\Dimitar\PycharmProjects\helloworld\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 24, in <module>
import urllib3
File "C:\Users\Dimitar\PycharmProjects\helloworld\venv\lib\site-packages\urllib3\__init__.py", line 7, in <module>
from .connectionpool import (
File "C:\Users\Dimitar\PycharmProjects\helloworld\venv\lib\site-packages\urllib3\connectionpool.py", line 30, in <module>
from .connection import (
ImportError: cannot import name 'port_by_scheme' from 'urllib3.connection' (C:\Users\Dimitar\PycharmProjects\helloworld\venv\lib\site-packages\urllib3\connection.py)

Weird behaviour with tweepy in Python?

I have python 2.7.9 on OS X (10.11). I have installed tweepy 3.5.0 and simplejson 3.8.1. When i write a program (IDE: textWrangler) for updating status of twitter account (by using tweepy) and run the program using command line it throws error on "import tweepy" in a program. However when i run the same code on python shell, it execute sucessfuly (without any error). Any suggestions or comments?
Traceback (most recent call last):
File "tweepytesting.py", line 1, in <module>
import tweepy
File "build/bdist.macosx-10.6-intel/egg/tweepy/__init__.py", line 14, in <module>
File "build/bdist.macosx-10.6-intel/egg/tweepy/api.py", line 12, in <module>
File "build/bdist.macosx-10.6-intel/egg/tweepy/binder.py", line 11, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/__init__.py", line 27, in <module>
from . import urllib3
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 33, in <module>
from .packages.ssl_match_hostname import CertificateError
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/packages/__init__.py", line 3, in <module>
from . import ssl_match_hostname
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py", line 3, in <module>
from ssl import CertificateError, match_hostname
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 90, in <module>
import textwrap
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 40, in <module>
class TextWrapper:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 82, in TextWrapper
whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
AttributeError: 'module' object has no attribute 'maketrans'
If I add this line:
import string; print(string)
just above import tweepy, then the following is printed:
<module 'string' from '/Users/yasirmuhammad/Desktop/learnpython/string.pyc'>

Categories

Resources