Scrapy shell does not open - python

I have a conda virtual environment called scrape where I have scrapy installed. But whenever I type in the command scrapy shell I get the following error.
$ scrapy shell Traceback (most recent call last): File "C:\Users\Ravi\anaconda3\envs\scrape\Scripts\scrapy-script.py", line 6, in <module> from scrapy.cmdline import execute File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\scrapy\__init__.py", line 12, in <module> from scrapy.spiders import Spider File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\scrapy\spiders\__init__.py", line 11, in <module> from scrapy.http import Request File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\scrapy\http\__init__.py", line 11, in <module> from scrapy.http.request.form import FormRequest File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\scrapy\http\request\form.py", line 16, in <module> from scrapy.utils.response import get_base_url File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\scrapy\utils\response.py", line 14, in <module> from twisted.web import http File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\twisted\web\http.py", line 183, in <module> from twisted.web._http2 import H2Connection File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\twisted\web\_http2.py", line 27, in <module> import h2.connection File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\h2\connection.py", line 23, in <module> from .events import ( File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\h2\events.py", line 14, in <module> from .settings import ChangedSetting, _setting_code_from_int File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\h2\settings.py", line 25, in <module> class SettingCodes(enum.IntEnum): File "C:\Users\Ravi\anaconda3\envs\scrape\lib\site-packages\h2\settings.py", line 60, in SettingCodes ENABLE_CONNECT_PROTOCOL = SettingsFrame.ENABLE_CONNECT_PROTOCOL AttributeError: type object 'SettingsFrame' has no attribute 'ENABLE_CONNECT_PROTOCOL'

Fixed:
The problem was that Scrapy was either using an older version of h2 or not using one at all. pip install --upgrade h2 fixed it.

Related

GOT TypeError: deprecated() got an unexpected keyword argument 'name' in boto3

Boto3 was running successfully the day before but when i ran today i am getting these errors
import boto3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/root1/.local/lib/python3.10/site-packages/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/home/root1/.local/lib/python3.10/site-packages/boto3/session.py", line 17, in <module>
import botocore.session
File "/home/root1/.local/lib/python3.10/site-packages/botocore/session.py", line 29, in <module>
import botocore.credentials
File "/home/root1/.local/lib/python3.10/site-packages/botocore/credentials.py", line 35, in <module>
from botocore.config import Config
File "/home/root1/.local/lib/python3.10/site-packages/botocore/config.py", line 16, in <module>
from botocore.endpoint import DEFAULT_TIMEOUT, MAX_POOL_CONNECTIONS
File "/home/root1/.local/lib/python3.10/site-packages/botocore/endpoint.py", line 24, in <module>
from botocore.awsrequest import create_request_object
File "/home/root1/.local/lib/python3.10/site-packages/botocore/awsrequest.py", line 24, in <module>
import botocore.utils
File "/home/root1/.local/lib/python3.10/site-packages/botocore/utils.py", line 32, in <module>
import botocore.httpsession
File "/home/root1/.local/lib/python3.10/site-packages/botocore/httpsession.py", line 28, in <module>
from urllib3.contrib.pyopenssl import orig_util_SSLContext as SSLContext
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 50, in <module>
import OpenSSL.SSL
File "/home/root1/.local/lib/python3.10/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import SSL, crypto
File "/home/root1/.local/lib/python3.10/site-packages/OpenSSL/SSL.py", line 19, in <module>
from OpenSSL.crypto import (
File "/home/root1/.local/lib/python3.10/site-packages/OpenSSL/crypto.py", line 3224, in <module>
utils.deprecated(
TypeError: deprecated() got an unexpected keyword argument 'name'
i tried uninstalling and reinstalling also tried out installing specific version
still getting an error
i am using it on ubuntu 22.0
the python version i am running
Python 3.10.6

Python urllib AttributeError

import urllib.request
fhand = urllib.request.urlopen("http://www.python.org")
for line in fhand:
print(line.decode().strip())
This code isn't working, I'm using python3 on windows10. Every time I run this code in command prompt using atom editor, I get the following error message:
Traceback (most recent call last):
File "C:\Users\isha\Downloads\py4e\trial.py", line 1, in <module>
import urllib.request
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 88, in <module>
import http.client
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\isha\AppData\Local\Programs\Python\Python38-32\lib\email\utils.py", line 29, in <module>
import socket
File "C:\Users\isha\Downloads\py4e\socket.py", line 5, in <module>
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
**AttributeError: partially initialized module 'socket' has no attribute 'AF_INET' (most likely due to a circular import)**
Help me with this code, also I'm not able to run urllib.request and related programs
Your code works well for me. Try delete 'C:\Users\isha\Downloads\py4e\socket.py' this file and run your code again.

Terminal cannot run selenium python

I wrote a python program that uses selenium. When I run it with spyder, it works perfectly. But when I run it on Terminal, I get this error message:
Traceback (most recent call last):
File "/Users/aldrin0n9/Documents/Python Projects/school.py", line 1, in <module>
from selenium import webdriver
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 29, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 26, in <module>
from .webelement import WebElement
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 27, in <module>
from selenium.webdriver.common.utils import keys_to_typing
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/utils.py", line 21, in <module>
import socket
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/socket.py", line 52, in <module>
import os, sys, io, selectors
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/selectors.py", line 11, in <module>
import math
File "/Users/aldrin0n9/Documents/Python Projects/math.py", line 3, in <module>
from selenium.webdriver.chrome.options import Options
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/site-packages/selenium/webdriver/chrome/options.py", line 20, in <module>
import platform
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/platform.py", line 116, in <module>
import sys, os, re, subprocess
File "/Users/aldrin0n9/opt/anaconda3/lib/python3.7/subprocess.py", line 168, in <module>
_PopenSelector = selectors.SelectSelector
AttributeError: module 'selectors' has no attribute 'SelectSelector'
Please help

Python request.py syntax error

I am new to Python 3.4.5 which I am learning online by watching videos with some good knowledge of C. I am trying to download an image via Python which I am unable to do because of this error.
Code:
import random
import urllib.request
def img(url):
full='name'+'.jpeg'
urllib.request.urlretrieve(url,full)
img("http://lorempixel.com/400/200")
Error:
Traceback (most recent call last):
File "image.py", line 2, in <module>
import urllib.request
File "/home/yuvi/pyth/urllib/request.py", line 88, in <module>
import http.client
File "/usr/local/lib/python3.4/http/client.py", line 69, in <module>
import email.parser
File "/usr/local/lib/python3.4/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/local/lib/python3.4/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/local/lib/python3.4/email/message.py", line 16, in <module>
from email import utils
File "/usr/local/lib/python3.4/email/utils.py", line 31, in <module>
import urllib.parse
File "/home/yuvi/pyth/urllib/parse.py", line 239, in <module>
_DefragResultBase.url.__doc__ = """The URL with no fragment identifier."""
AttributeError: readonly attribute
Try:
def img(url): full='name'+'.jpeg';urllib.urlretrieve(url,full)
urllib.request does not exist in Python 2.x, which seems to be your case
so don't try to import that in second line of your code
plus you made a typo (forgot semicolon) which works as a statement separator while writing inline function statements.
Similar to:
def img(url):
full='name'+'.jpeg'
urllib.urlretrieve(url,full)

Cannot `import smtplib`

When ever I try to import smtplib in the Python interpreter, I get this error:
ImportError: cannot import name fix_eols
How can I fix this?
Edit:
Here is the full stack trace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/utils.py", line 32, in <module>
from email._parseaddr import quote
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/_parseaddr.py", line 16, in <module>
import time, calendar
File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>
File "/usr/local/lib/python2.7/site-packages/apiclient/__init__.py", line 19, in <module>
from googleapiclient import discovery
File "/usr/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 38, in <module>
from email.generator import Generator
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/generator.py", line 15, in <module>
from email.header import Header
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/header.py", line 16, in <module>
import email.quoprimime
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/email/quoprimime.py", line 49, in <module>
from email.utils import fix_eols
ImportError: cannot import name fix_eols
Just to point out how to detect this kinds of errors (since it does happen from time to time):
Pay attention to the stacktrace. In this example, the problem can be seen in the line:
File "/Users/aaronblock/Documents/programming/scripts/calendar.py", line 7, in <module>
which certainly indicates wrong file being imported when we're trying to import a system-wide library.
I had a file called "calendar.py" which messes up my Python environment because smtplib needs calendar.py in order to work. Deleting calendar.py solved my problem.

Categories