I am having trouble using the URL object from the web package of the pattern library. When I try to download text from a URL object, I get a permission error.
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pattern.web
>>> urlObject=pattern.web.URL("http://google.com")
>>> urlResponse = urlObject.download()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pattern/web/__init__.py", line 426, in download
cache[id] = data
File "/usr/local/lib/python2.7/dist-packages/pattern/web/cache/__init__.py", line 96, in __setitem__
f = open(self._hash(k), "wb")
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pattern/web/cache/tmp/c7b920f57e553df2bb68272f61570210'
I had no problem with this when running python with sudo, but I would like to understand what is going on here and how I can avoid granting root permissions to python just to download a URL. Does anyone have any insight on this issue?
Running Ubuntu 12.04, python 2.7.3, pattern version 2.6
You need to run it in a directory where you have write access because it is attempting to create a cache file.
(Probably want to clean up cache files from when you ran it with sudo because it seems to have polluted your system directories with chaff.)
It looks like you could try
urlResponse = urlObject.download(cached=False)
to disable the caching functionality.
Changing the owner/group of /usr/local/lib/python2.7/dist-packages/pattern/web/ to my user seems to have resolved the issue. I installed pattern via pip, nothing fancy, so I am assuming this is a bug and the permissions were too tight when pattern was installed.
Related
Running 3.3 python on CentOS 7.
Tryin' to write simple script but can't get pexpect module to work as I want
if I use interpreter python 3.3, I can write this commands correctly
[root#localhost expect]# python3.3
Python 3.3.3 (default, Apr 7 2015, 02:31:24)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
>>> child = pexpect.spawn('telnet 10.1.1.1')
but If I run file pexpect.py with exactly same commands, I get
[root#localhost expect]# python3.3 /usr/etc/pexpect.py
Traceback (most recent call last):
File "/usr/etc/pexpect.py", line 1, in <module>
import pexpect
File "/usr/etc/pexpect.py", line 3, in <module>
child = pexpect.spawn('telnet 10.1.1.1');
AttributeError: 'module' object has no attribute 'spawn'
I found some similar info in the google, advice was to move .py file to another folder.
It didn't work for me.
Another advice was to delete " pycache" folder (I've got same in my pexpect.py location), but it didn't work aswell. Errors are still the same, this folder are still created after running the script (trying, I mean).
Any ideas?
You have called your file pexpect.py. You need to rename it to something else as you are importing from your file not the pexpect module. You also need to delete any .pyc in the same folder. It does not matter where you move your script, the current folder is still going to be in the path before where the actual pexpect module is.
I'm trying to get started with Apache Spark. I'd like to use it via python. However, when I run pyspark from the command line I get the following error message:
C:\Programs\Apache\Spark\spark-1.2.0-bin-hadoop2.4\bin>pyspark.cmd
Running python with PYTHONPATH=C:\Programs\Apache\Spark\spark-1.2.0-bin-hadoop2.
4\bin\..\python\lib\py4j-0.8.2.1-src.zip;C:\Programs\Apache\Spark\spark-1.2.0-bi
n-hadoop2.4\bin\..\python;
Python 2.7.8 |Anaconda 2.1.0 (32-bit)| (default, Jul 2 2014, 15:13:35) [MSC v.1
500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
find: 'version': No such file or directory
else was unexpected at this time.
Traceback (most recent call last):
File "C:\Programs\Apache\Spark\spark-1.2.0-bin-hadoop2.4\bin\..\python\pyspark
\shell.py", line 45, in <module>
sc = SparkContext(appName="PySparkShell", pyFiles=add_files)
File "C:\Programs\Apache\Spark\spark-1.2.0-bin-hadoop2.4\python\pyspark\contex
t.py", line 102, in __init__
SparkContext._ensure_initialized(self, gateway=gateway)
File "C:\Programs\Apache\Spark\spark-1.2.0-bin-hadoop2.4\python\pyspark\contex
t.py", line 211, in _ensure_initialized
SparkContext._gateway = gateway or launch_gateway()
File "C:\Programs\Apache\Spark\spark-1.2.0-bin-hadoop2.4\python\pyspark\java_g
ateway.py", line 73, in launch_gateway
raise Exception(error_msg)
Exception: Launching GatewayServer failed with exit code 255!
Warning: Expected GatewayServer to output a port, but found no output.
When I try and run the scala interface by running spark-shell I get the message:
find: 'version': No such file or directory
else was unexpected at this time.
I cant find any info on this error online, other than
which turned out to be a dead end.
https://issues.apache.org/jira/browse/SPARK-3808
Please help!
I had the same problem in spark 1.2.0 but not in spark 1.0.2.
The reason was in my case that I had cygwin in the DOS classpath.
Spark uses the find command in the file 'spark-class2.cmd', which used then the cygwin find command instead of the DOS find command, which works somewhat different.
I removed cygwin from the DOS PATH, which solved the problem.
Regards, Felix
I am trying to utilize the python-iptables package to list iptables rules in a web app. When I add the iptc package to my environment, I get the below error. I used yum 'provides' to find where the libxtables.so.4 file comes from and found that the iptables and iptables-devel packages were the appropriate choice in CentOS 6.4 x64. I upgraded those packages but it did not change the error.
Does anyone have any suggestions about how I can resolve this?
pgrace#ny-misc01:~/repos/python-iptables/libxtwrapper$ python
Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import iptc
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python2.6/site-packages/iptc/__init__.py", line 10, in
from ip4tc import Table, Chain, Rule, Match, Target, Policy, IPTCError
File "/usr/lib64/python2.6/site-packages/iptc/ip4tc.py", line 11, in
from xtables import (XT_INV_PROTO, NFPROTO_IPV4, XTablesError, xtables,
File "/usr/lib64/python2.6/site-packages/iptc/xtables.py", line 744, in
class xtables(object):
File "/usr/lib64/python2.6/site-packages/iptc/xtables.py", line 757, in xtables
_xtables_afinfo = ct.c_void_p.in_dll(_lib_xtables, "afinfo")
ValueError: /lib64/libxtables.so.4: undefined symbol: afinfo
>>>
See this: https://github.com/ldx/python-iptables/issues/25
This is a known problem, old versions of libxtables declared afinfo as static, thus it is not accessible for python-iptables. There is a possible workaround, though - please keep an eye on the ticket, it will be updated as soon as there has been progress.
Another solution is to update iptables on your machine.
Disclaimer: I am the maintainer of python-iptables.
Update: this should be fixed now.
I'm trying to use generateDS under windows, which uses os.tmpfile. Unfortunately, os.tmpfile doesn't work for me:
(oneclickcos) C:\Users\Marcin\Documents\oneclickcos\xsd>python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.tmpfile()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 13] Permission denied
>>>
I've got all my temp directories set with full control for everyone, so that shouldn't be the problem.
What could be causing this?
Run the script as administrator (right click on the script and select 'run as administrator'), the script lacks the permissions to execute os.tmpfile().
Edit:
As I see you're using the interpreter, simply run the interpreter as administrator. If you're accessing it though a terminal, running the terminal as administrator should be sufficient.
As Griffin pointed out the problem is that the os.tmpfile() tries to create a file in the root directory. If you don't like to run the script as administrator you can use os.tmpnam() and handle the file yourself.
Warning: Use of tmpnam() is vulnerable to symlink attacks
I'm running into a weird problem where I'm unable to connect to PostgreSQL from a Python 3.2 install. I'm running Fedora 15 and have installed Python3 and PostgerSQL9 from the Fedora repositories using yum. Does anyone have any ideas on why I'm seeing this problem and how to correct it? Google searches haven't been turning up anything.
I've changed the username, password, and database, but my pg_hba.conf file is correct.
import postgresql
t = postgresql.open(user='validuser', password='secret', database='some_database')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.2/site-packages/postgresql/__init__.py", line 88, in open
c.connect()
File "/usr/lib64/python3.2/site-packages/postgresql/driver/pq3.py", line 2419, in connect
pq = Connection3(sf, startup, password = password,)
File "/usr/lib64/python3.2/site-packages/postgresql/protocol/client3.py", line 514, in __init__
element.Startup(**startup), password
TypeError: keyword arguments must be strings
As a side note, I get this same error if I try to connect using different user, password, database combinations, and also if I use a pq://user:password#host/database connection string instead of keywords, both to localhost and to remote hosts.
I think that probably is some bug in python3-postgresql package, but it looks like it works after little change. Edit this file (probably /usr/lib64 for 64 bit installations):
/usr/lib/python3.2/site-packages/postgresql/protocol/client3.py
Change (line 514):
element.Startup(**startup), password
to:
element.Startup(startup), password
After that I made simple connection (I changed pg_hba.conf host methods to md5) and it looks ok:
[grzegorz#localhost Desktop]$ python3
Python 3.2 (r32:88445, Feb 21 2011, 21:12:33)
[GCC 4.6.0 20110212 (Red Hat 4.6.0-0.7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import postgresql
>>> db = postgresql.open("pq://grzegorz:12345#localhost/grzegorz")
>>> ps = db.prepare("SELECT version()")
>>> ps()
[('PostgreSQL 9.0.4 on i386-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.6.0 20110530 (Red Hat 4.6.0-9), 32-bit',)]
>>> ps = db.prepare("TABLE t")
>>> ps()
[(1, 'aaa'), (2, 'bbb'), (3, 'ccc')]
>>>
Just a guess, but python is probably passing unicode to postgres and it's expecting strings.
You can also use another module - psycopg2 to connect to postgresql
http://initd.org/psycopg/download/