Tornado On RPi not working - python

Hello im trying to use tornado websockets on my Raspberry PI and i get this error
File "socket.py", line 1, in <module>
import tornado.httpserver
File "/usr/local/lib/python2.7/dist-packages/tornado/httpserver.py", line 31, in <module>
import socket
File "/root/socket.py", line 2, in <module>
import tornado.websocket
File "/usr/local/lib/python2.7/dist-packages/tornado/websocket.py", line 28, in <module>
import tornado.escape
File "/usr/local/lib/python2.7/dist-packages/tornado/escape.py", line 31, in <module>
from urllib.parse import parse_qs as _parse_qs # py3
File "/usr/lib/python2.7/urllib.py", line 850, in <module>
class ftpwrapper:
File "/usr/lib/python2.7/urllib.py", line 854, in ftpwrapper
timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
AttributeError: 'module' object has no attribute '_GLOBAL_DEFAULT_TIMEOUT'
the code im using is from the website as a example

Don't call your file socket.py. It's confilicting with the python library module of the same name.
Make sure you delete socket.pyc too if there is one.

Related

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.

Import 'transport' error in asyncio attributes

I am trying to make a discord bot, but I get the following weird error where it can not import asyncio.Transport, although I am able to use it normally outside this code.
The code:
import asyncio
import os
import discord
from dotenv import load_dotenv
The error message:
Traceback (most recent call last):
File "dis.py", line 1, in <module>
import asyncio
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\asyncio\__init__.py", line 21, in <module>
from .base_events import *
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", line 19, in <module>
import inspect
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\inspect.py", line 36, in <module>
import dis
File "C:\Users\A.Gawish\dis.py", line 3, in <module>
import discord
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\__init__.py", line 23, in <module>
from .client import Client
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 34, in <module>
import aiohttp
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\__init__.py", line 6, in <module>
from .client import (
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\client.py", line 32, in <module>
from . import hdrs, http, payload
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\http.py", line 7, in <module>
from .http_parser import (
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\http_parser.py", line 14, in <module>
from .base_protocol import BaseProtocol
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\base_protocol.py", line 4, in <module>
from .tcp_helpers import tcp_nodelay
File "C:\Users\A.Gawish\AppData\Local\Programs\Python\Python36\lib\site-packages\aiohttp\tcp_helpers.py", line 20, in <module>
def tcp_keepalive(transport: asyncio.Transport) -> None:
AttributeError: module 'asyncio' has no attribute 'Transport'
Your filename was dis.py, which is used in another module. I resolved a similar issue by ensuring the filename is different from any other existing files in Lib
If you look at your error messages, it is indicating Python36. If Transport in asyncio was only released in Python37, you need to change the pathing in whatever program you're using to write the code in as it's looking at Python36.
Testing it as the command prompt would show that your system sees Python37 but your code doesn't. Fix the pathing and it should work then.

Flask, wsgi and deploy

(pardon my english)
Hello,
I've a problem for a deploy on a gandi server.
After a git push on a gandi server, I'm proceeding a deploy :
ssh [url] deploy default.git
I obtain an "Internal Error Server".
My log/www/uwsgi.log said :
Traceback (most recent call last):
File "/srv/data/web/vhosts/default/wsgi.py", line 1, in <module>
from run import app as application
File "./run.py", line 1, in <module>
from app import app as application
File "./app/__init__.py", line 1, in <module>
from flask import Flask
File "/srv/data/web/vhosts/default/local/lib/python3.6/site-packages/flask/__init__.py", line 19, in <module>
from jinja2 import Markup, escape
File "/srv/data/web/vhosts/default/local/lib/python3.6/site-packages/jinja2/__init__.py", line 82, in <module>
_patch_async()
File "/srv/data/web/vhosts/default/local/lib/python3.6/site-packages/jinja2/__init__.py", line 78, in _patch_async
from jinja2.asyncsupport import patch_all
File "/srv/data/web/vhosts/default/local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 13, in <module>
import asyncio
File "/opt/python-3.6/usr/lib/python3.6/asyncio/__init__.py", line 21, in <module>
from .base_events import *
File "/opt/python-3.6/usr/lib/python3.6/asyncio/base_events.py", line 17, in <module>
import concurrent.futures
File "/opt/python-3.6/usr/lib/python3.6/concurrent/futures/__init__.py", line 17, in <module>
from concurrent.futures.process import ProcessPoolExecutor
File "/opt/python-3.6/usr/lib/python3.6/concurrent/futures/process.py", line 55, in <module>
from multiprocessing.connection import wait
File "/opt/python-3.6/usr/lib/python3.6/multiprocessing/connection.py", line 23, in <module>
from . import util
File "/opt/python-3.6/usr/lib/python3.6/multiprocessing/util.py", line 17, in <module>
from subprocess import _args_from_interpreter_flags
File "/opt/python-3.6/usr/lib/python3.6/subprocess.py", line 136, in <module>
import _posixsubprocess
ImportError: /srv/data/web/vhosts/default/local/lib/python3.6/lib-dynload/_posixsubprocess.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _Py_set_inheritable_async_safe
I have not idea how can I solve this problem... ?
Anyone understand this problem ? Thank you

urllib doesn't work properly

I am trying to use urllib for the simple request as in below:
import urllib
my_url = "https://realpython.com/practice/aphrodite.html"
my_open = urllib.request.urlopen(my_url)
my_op = my_open.read().decode('utf-8')
print(my_op)
When I run code it returns me request from my database, which is not related to the urllib. Moreover, I got an error as in below:
import urllib.request
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/request.py", line 88, in <module>
import 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 29, in <module>
import socket
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 52, in <module>
import os, sys, io, selectors
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/selectors.py", line 290, in <module>
class SelectSelector(_BaseSelectorImpl):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/selectors.py", line 317, in SelectSelector
_select = select.select
AttributeError: module 'select' has no attribute 'select'
I can uninstall and install any library except urllib. Please guide me about this error.
I created a separate file with the name of select.py and didn't include any code to that. After that, I didn't get any error.

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)

Categories