顯示具有 Python 標籤的文章。 顯示所有文章
顯示具有 Python 標籤的文章。 顯示所有文章

2019年7月24日 星期三

Install boto3 on MAC

System Information

# sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.5
BuildVersion:   18F132

Check pip version

# pip --version
pip 19.1.1 from /Library/Python/2.7/site-packages/pip-19.1.1-py2.7.egg/pip (python 2.7)

Install boto3

  • Pre-requirement Package
if you see an error like below
ERROR: Could not install packages due to an EnvironmentError: [Errno 1] Operation not permitted: '/System/Library/Frameworks/Python.framework/Versions/2.7/man'
and then you have one parameter missing needs add --user
# sudo pip install matplotlib --user
  • Install boto3
if you see an error like below
ERROR: Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
and then you should add the parameter --ignore-installed six
# sudo pip install boto3 --ignore-installed six
Now you can use boto3 call AWS API
Reference:

2017年2月7日 星期二

uwsgi unix domain socket error

uwsgi unix domain socket error

Nginx Error Message

2017/02/08 14:33:15 [crit] 31592#31592: *1 connect() to unix:///tmp/service.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.10, server: beta-hello.com, request: "GET /traffic_funnel HTTP/1.1", upstream: "uwsgi://unix:///tmp/service.sock:", host: "beta-hello.com"

解決辦法

原本都是把socket放在 /tmp 下,但好像每個服務看到的 /tmp 是不一樣的,所以還放在 /var/run 或是放在 /run 底下才會正常

原文

You can't place sockets intended for interprocess communication in /tmp.
For security reasons, recent versions of Fedora use namespaced temporary directories, meaning every service sees a completely different /tmp and can only see its own files in that directory.
To resolve the issue, place the socket in a different directory, such as /run (formerly known as /var/run).

Reference

2016年11月8日 星期二

Python library BeautifulSoup4

OS: openSUSE Leap 42.1 (x86_64)
# sudo pip install beautifulsoup4

from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("http://pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html.read())
print(bsObj.h1)
用上面這個程式跑會有Warning,如下
/usr/lib/python3.4/site-packages/bs4/__init__.py:181: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.paser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently

The code that caused this warning is on line 5 of the file myScrap.py. To get rid of this warning, change code that looks like this:

 BeautifulSoup([your markup])

to this:

 BeautifulSoup([your markup], "html.parser")

  markup_type=markup_type))
依照噴出的Warning做程式的修改,所以就變成下面的寫法了。
from urllib.request import urlopen
from bs4 import BeautifulSoup

html = urlopen("http://pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html, 'html.parser)
print(bsObj.h1)
上面程式中的意思把 html 內容轉換成 BeautifulSoup的物件後,並把 html中的標籤 h1 給顯示出來。
bsObj.h1 也可以改寫成
bsObj.html.body.h1
bsObj.html.h1
bsObj.body.h1
得到的結果都會是一樣的