I've just bought synology NAS (DS213J) and I am trying to run a python script on it.
My python script:
1 #!/opt/bin/python
2
3 import urllib
4 response = urllib.urlopen('http://google.com')
5 html = response.read()
6 print html
when I run this script, I've got this output:
Traceback (most recent call last):
File "/opt/bin/test.py", line 4, in <module>
response = urllib.urlopen('http://google.com')
File "/opt/lib/python2.5/urllib.py", line 82, in urlopen
return opener.open(url)
File "/opt/lib/python2.5/urllib.py", line 190, in open
return getattr(self, name)(url)
File "/opt/lib/python2.5/urllib.py", line 272, in open_http
import httplib
File "/opt/lib/python2.5/httplib.py", line 70, in <module>
import mimetools
File "/opt/lib/python2.5/mimetools.py", line 6, in <module>
import tempfile
File "/opt/lib/python2.5/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/opt/lib/python2.5/random.py", line 58, in <module>
SG_MAGICCONST = 1.0 + _log(4.5)
OverflowError: math range error
I also tried use urllib2 with no success.
Script:
1 #!/opt/bin/python
2
3 import urllib2
4 response = urllib2.urlopen('http://google.com')
5 html = response.read()
6 print html
console output:
Traceback (most recent call last):
File "/opt/bin/test.py", line 3, in <module>
import urllib2
File "/opt/lib/python2.5/urllib2.py", line 92, in <module>
import httplib
File "/opt/lib/python2.5/httplib.py", line 70, in <module>
import mimetools
File "/opt/lib/python2.5/mimetools.py", line 6, in <module>
import tempfile
File "/opt/lib/python2.5/tempfile.py", line 33, in <module>
from random import Random as _Random
File "/opt/lib/python2.5/random.py", line 58, in <module>
SG_MAGICCONST = 1.0 + _log(4.5)
OverflowError: math range error
I have no idea what these errors mean; I've googled some with no success. The script above is part of a larger script to download subtitles for movies (I've just took error part from the bigger script and posted here).
I wrote that this script is running on synology DS213j, because I think that may be something with python installation. Generally I had problem with installing ipkg
for my synylogy. I ended up with this tutorial. After installing bootstrap from the tutorial, I just run ipkg install python
and package was installed successfully. My python version is Python 2.5.6
.
Thanks
The problem is in #!/opt/bin/python
, run which python
in order to figure out what is your python binary full path is.
As you can see your list of are ok:
>>> import urllib
>>> response = urllib.urlopen('http://google.com')
>>> html = response.read()
>>> print html
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="iw" dir="rtl"><head><meta content="/images/google_favicon_128.png" itemprop="image"><title>Google</title>[...]</body></html>
I think you should use python 2.7 or follow
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7
Using ipkg
:
ipkg update
ipkg install python27
python2.7
will start the python interpreter.