MacOS读写ntfs格式硬盘

发布在 Mac

系统OS X 10.11,之前就有发现ntfs格式的移动硬盘在mac上只能读不能写,通俗点说就是不能保存文件。

总体而言解决方法不外乎4种:

  1. 硬盘在Mac上格式化成ExFAT这种通用格式
  2. 安装第三方插件,比如Paragon NTFS for MAC(收费)
  3. 安装osxfuse+ntfs-3g(命令行)
  4. 修改配置文件打开原生支持方法

首先硬盘里有东西就把第一种方式排除了,缺钱也不想用破解版的第二种也排除,虽说mac也是类unix系统不过看网上改的文件内容也不是特别明白原理排除,所以使用第三种方式吧。

首先安装这2个东西:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[x@bogon ~ ]$ brew install Caskroom/cask/osxfuse
==> Installing brew-cask from caskroom/homebrew-cask
==> Cloning https://github.com/caskroom/homebrew-cask.git
Cloning into '/Library/Caches/Homebrew/brew-cask--git'...
remote: Counting objects: 3193, done.
remote: Compressing objects: 100% (3117/3117), done.
remote: Total 3193 (delta 84), reused 712 (delta 59), pack-reused 0
Receiving objects: 100% (3193/3193), 5.81 MiB | 18.00 KiB/s, done.
Resolving deltas: 100% (84/84), done.
Checking connectivity... done.
Note: checking out 'c216698c730540185ba88f14722fe8b74174eb0d'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
==> Checking out tag v0.57.0
? /usr/local/Cellar/brew-cask/0.57.0: 2921 files, 12M, built in 4.9 minutes
==> brew cask install Caskroom/cask/osxfuse
==> We need to make Caskroom for the first time at /opt/homebrew-cask/Caskroom
==> We'll set permissions properly so we won't need sudo in the future
Password:
==> Caveats
You must reboot for the installation of osxfuse to take effect.
==> Downloading http://downloads.sourceforge.net/project/osxfuse/osxfuse-2.8.1/osxfuse-2.8.1.dmg
######################################################################## 100.0%
==> Running installer for osxfuse; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
==> installer: Package name is FUSE for OS X (OSXFUSE)
==> installer: Installing at base path /
==> installer: The install was successful.
? osxfuse staged at '/opt/homebrew-cask/Caskroom/osxfuse/2.8.1' (6 files, 8.5M)
[x@bogon ~ ]$ brew install homebrew/fuse/ntfs-3g
==> Tapping homebrew/fuse
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-fuse'...
remote: Counting objects: 31, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 31 (delta 0), reused 23 (delta 0), pack-reused 0
Unpacking objects: 100% (31/31), done.
Checking connectivity... done.
Tapped 26 formulae (80 files, 324K)
==> Installing ntfs-3g from homebrew/homebrew-fuse
==> Downloading https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2015.3.14.tgz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/ntfs-3g/2015.3.14 --exec-prefix=/usr/local/Cellar/ntfs-3g/2015.3.14 --m
==> make
==> make install
? /usr/local/Cellar/ntfs-3g/2015.3.14: 87 files, 2.0M, built in 78 seconds

安装完成后使用cmd+r重启进入恢复模式,这里就不截图了,在恢复模式下打开终端输入
csrutil disable

然后正常重启,再打开终端

1
2
sudo mv /sbin/mount_ntfs /sbin/mount_ntfs.bak
sudo ln -s /usr/local/sbin/mount_ntfs /sbin/mount_ntfs

有点unix基础的应该都明白,不详细说了。修改完成后再进入恢复模式,打开终端输入
csrutil enable
再正常重启即可。

修改后将移动硬盘连接在finder中是不显示图标的了,不过默认就挂载在/Volumes目录下,或者打开磁盘工具,右键点击选择“在finder中打开”也可以。

如果想恢复,依然是按照上面的步骤,把mount_ntfs.bak改回原名即可。

评论和分享

suds库使用小记

发布在 Python

虽说接触过的大部分接口都是以restfullapi的形式返回json数据,但最近有些接口是soap的,如果只是需要一个python的soap客户端的话,suds库是十分不错的一个选择,文档

使用pip安装即可,最基础的使用方法如下,示例来源官网:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from suds.client import Client
url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl'
client = Client(url)
print client
Suds - version: 0.3.3 build: (beta) R397-20081121
Service (WebServiceTestBeanService) tns="http://test.server.enterprise.rhq.org/"
Prefixes (1):
ns0 = "http://test.server.enterprise.rhq.org/"
Ports (1):
(Soap)
Methods:
addPerson(Person person, )
echo(xs:string arg0, )
getList(xs:string str, xs:int length, )
getPercentBodyFat(xs:string name, xs:int height, xs:int weight)
getPersonByName(Name name, )
hello()
testExceptions()
testListArg(xs:string[] list, )
testVoid()
updatePerson(AnotherPerson person, name name, )
Types (23):
Person
Name
Phone
AnotherPerson

其中methods就是实现各个功能的方法,types则定义了数据类型:

1
2
result = client.service.getPercentBodyFat('jeff', 68, 170)
print result

比如string,int等简单类型就不多说了,如果想知道Person类型是什么,则可以使用:

1
2
person = client.factory.create('Person')
print person

来查看具体细节:

1
2
3
4
5
6
7
8
9
10
(Person)=
{
phone = []
age = NONE
name(Name) =
{
last = NONE
first = NONE
}
}

同理phone,name都是一种类型,可以使用ractory.create方法进行创建并赋值:

1
2
3
4
5
6
7
8
9
10
phone = client.factory.create('Phone')
phone.npa = 202
phone.nxx = 555
phone.number = 1212
name = client.factory.create('Name')
name.first = 'Elmer'
name.last = 'Fudd'
person.name = name
person.age = 35
person.phone = [phone]

然后就可以调用相关的方法了:client.service.addPerson(person)

有些接口还需要设置soap:Header属性,使用client.set_options(soapheaders=(userid,password))

这里需要注意的就是如果header中有多个节点的话,要使用一个元组添加而不是调用多次set_options函数.

再比较有用的就是如果想看suds构造出的xml信息的话,使用

1
2
3
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)

就可以了,如果还想看更详细的信息,比如请求头,状态码等,还可以使用
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
至于更高级的用法,比如安全认证,xml信息修改注入,多server调用等文档描述的也很详细.

其实soap接口的本质就是向某个url以post方式提交一个xml格式的字符串,当然http头信息也需要相应变化,比如:

1
2
3
4
headers = {"Content-Type": "text/xml; charset=utf-8",
"SOAPAction": "http://www.xxxx.com/service/xxxx",
"Host": "www.xxxx.com"
}

可以使用requests以及urllib2等库发送请求,得到结果使用正则或lxml进行处理.

之前我由于某些原因不想使用suds就是这么做的,这种方法有2点需要注意:

  1. 构造xml字符串的编码问题,以及特殊符号转意:’&’转成’&amp;‘,”<”转成”&lt;
  2. 某些函数必须进行顺序调用(比如必须先调用登录函数才能调用查询函数…),注意把上一个调用结果的cookie带入到下一个调用中,建议使用requests库的session进行自动处理

评论和分享

最近使用requests库进行操作时总出现如下警告:

1
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

虽然不影响程序执行,不过看着一个警告还是心理不舒服.

解决办法很简单,安装几个包即可pip install pyopenssl ndg-httpsclient pyasn1

安装过程中可能出现某些头文件不存在的错误,比如

1
2
openssl/aes.h: No such file or directory
fatal error: ffi.h: No such file or directory

安装对应的dev包即可,比如ubuntu下就是
sudo apt-get install libffi-dev libssl-dev

评论和分享

  • 第 1 页 共 1 页
作者的图片

Roy

微信公众号:hi-roy


野生程序猿


China