Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest 引用转储的LinkedIn API数据_Rest_Python 2.7_Linkedin_Pickle - Fatal编程技术网

Rest 引用转储的LinkedIn API数据

Rest 引用转储的LinkedIn API数据,rest,python-2.7,linkedin,pickle,Rest,Python 2.7,Linkedin,Pickle,这里有一个我不知道怎么解决的小问题,我想你们可以告诉我该怎么走。我已经成功地使用LinkedIn REST API(XML和JSON)提取了所有连接数据,并将它们转储(前者使用cPickle插件)。问题是我需要引用数据中的单个字段,因此决定使用XML,因为它似乎是迄今为止最容易使用的。当我引用.pickle文件中的特定字段时,会出现以下错误: AttributeError: 'str' object has no attribute 'location' 但是,使用记事本打开pickle文件时

这里有一个我不知道怎么解决的小问题,我想你们可以告诉我该怎么走。我已经成功地使用LinkedIn REST API(XML和JSON)提取了所有连接数据,并将它们转储(前者使用cPickle插件)。问题是我需要引用数据中的单个字段,因此决定使用XML,因为它似乎是迄今为止最容易使用的。当我引用.pickle文件中的特定字段时,会出现以下错误:

AttributeError: 'str' object has no attribute 'location'
但是,使用记事本打开pickle文件时,我可以看到所有连接的位置字段都以XML格式存储。真奇怪

这是我的推荐代码:

import cPickle

connections_data = 'linkedin_connections.pickle'
response = cPickle.load(open(connections_data))

print response

locations = [ec.location for ec in response]
我设置了一个print函数来显示文件中的内容,所有数据都使用restapi的people调用显示为正常的XML输出。XML数据如下所示:

<person>
<id>ID_number</id>
<first-name>blah</first-name>
<last-name>blah</last-name>
<headline>Business Development and Sales Executive at Computaris</headline>
<picture-url>picture_url</picture-url>
<api-standard-profile-request>
  <url>profile_request</url>
  <headers total="1">
    <http-header>
      <name>x-li-auth-token</name>
      <value>name</value>
    </http-header>
  </headers>
</api-standard-profile-request>
<site-standard-profile-request>
  <url>request_url</url>
</site-standard-profile-request>
<location>
  <name>location</name>
  <country>
    <code>country_code</code>
  </country>
</location>
<industry>industry</industry>

任何帮助都将不胜感激