小编Vir*_*put的帖子

检查JSON(对象属性是否存在)并将其打印为解码的unicode

我从Instagram API获得以下数据,我试图propertycaption使用以下代码获取文本:

data = simplejson.load(info) # info is retrieved using the urllib2 
    for post in data['data']: 
        if post['caption'] is not "null":
            try:
                post['caption']['text']
            except NameError:
                post['caption']['text'] = 0
            if post['caption']['text'] is not 0:
                print post['caption']['text']
Run Code Online (Sandbox Code Playgroud)

但是在打印unicode字符串时我一直收到TypeError: 'NoneType' object has no attribute '__getitem__'错误+ UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-5: cha racter maps to <undefined>错误

以下是检索和存储的JSON数据 info

{
   "pagination":{
      "next_url":"https:\/\/api.instagram.com\/v1\/users\/self\/feed?access_token=184046392.f59def8.c5726b469ad2462f85c7cea5f72083c0&count=3&max_id=247821697921944007_6064449",
      "next_max_id":"247821697921944007_6064449"
   },
   "meta":{
      "code":200
   },
   "data":[
      {
         "attribution":null,
         "tags":[
            "usausausa", …
Run Code Online (Sandbox Code Playgroud)

python unicode json simplejson

16
推荐指数
2
解决办法
7万
查看次数

Json转储dict抛出TypeError:keys必须是一个字符串

我试图转换以下内容dict:

 {
     'post_engaged': 36,
     'post_impressions': 491,
     'post_story': 23,
     'comment_count': 6,
     'created_time': '03:02 AM, Sep 30, 2012',
     'message': 'Specialities of Shaktis and Pandavas. \n While having power, why there isn\\u2019t',
     < built - in function id > : '471662059541196',
     'status_type': 'status',
     'likes_count': 22
 } {
     'post_engaged': 24,
     'text': '30 Sept 2012 Avyakt Murlli ( Dual Voice )',
     'post_story': 8,
     'comment_count': 3,
     'link': 'http:\\/\\/www.youtube.com\\/watch?v=VGmFj8g7JFA&feature=youtube_gdata_player',
     'post_impressions': 307,
     'created_time': '03:04 AM, Sep 30, 2012',
     'message': 'Not available',
     < built - in function …
Run Code Online (Sandbox Code Playgroud)

python json simplejson

15
推荐指数
3
解决办法
2万
查看次数

如何解决'abt_utf8_nextCharSafeBody'崩溃问题

我见过大约177次.

这是我从Splunk Mint得到的堆栈跟踪.

这次崩溃的任何解决方法?

主要发生在iOS 8.3上

0   IOKit   IOServiceAddInterestNotification (in IOKit) + 44
1   UIKit   _MatchedBatteries (in UIKit) + 100
2   UIKit   -[UIDevice setBatteryMonitoringEnabled:] (in UIKit) + 208
3   Earthmiles  -[DataFixture appendBaseValues] (in Earthmiles) + 2180
4   Earthmiles  -[DataFixture init] (in Earthmiles) + 80
5   Earthmiles  -[NetworkDataFixture init] (in Earthmiles) + 56
6   Earthmiles  SplunkNSURLConnectionSendSynchronousRequestReturningResponseError (in Earthmiles) + 164
7   Earthmiles  abt_utf8_nextCharSafeBody (in Earthmiles) + 41984
8   libdispatch.dylib   _dispatch_call_block_and_release (in libdispatch.dylib) + 24
9   libdispatch.dylib   _dispatch_client_callout (in libdispatch.dylib) + 16 …
Run Code Online (Sandbox Code Playgroud)

crash splunk ios

6
推荐指数
0
解决办法
273
查看次数

从UTC偏移量获取时区缩写

我的数据库中的UTC偏移量为用户提供:

+5:30 
Run Code Online (Sandbox Code Playgroud)

如何使用Python从此UTC偏移量中获取时区缩写?

+5:30 => IST
Run Code Online (Sandbox Code Playgroud)

甚至可以使用Python来做到这一点吗?

python timezone

3
推荐指数
1
解决办法
2510
查看次数

获取列表中具有相同最大值的最后一个索引

我有以下清单:

 a = [100, 34, 2, 100]
Run Code Online (Sandbox Code Playgroud)

我想要最大的索引值:

 $ a.index(max(a))
 Returns: 0
Run Code Online (Sandbox Code Playgroud)

什么是在这种情况下获得的最后一个索引(具有最大值)的Python的方式3

(因为最大值重复多次。)

python

2
推荐指数
1
解决办法
1506
查看次数

Google Apps 脚本机器人每分钟重复抓取网站

就在一个小时前,我启动了tailingapache日志文件(访问日志),从那时起,我注意到这个奇怪的用户代理(无法在Google的官方文档中找到它)。

我对此感到怀疑,因为我在 Google 网站上找不到有关此用户代理的任何内容,

("Mozilla/5.0 (compatible; GoogleApps script; +http://script.google.com/bot.html))
Run Code Online (Sandbox Code Playgroud)

它一整天、每分钟都在抓取我们网站的登录页面。

这是日志片段:

72.14.199.55 - - [07/Aug/2013:16:06:28 +0000] "GET / HTTP/1.1" 302 639 "-" "Mozilla/5.0 (compatible; GoogleApps script; +http://script.google.com/bot.html)"

72.14.199.55 - - [07/Aug/2013:16:06:28 +0000] "GET /accounts/login/ HTTP/1.1" 200 3780 "-" "Mozilla/5.0 (compatible; GoogleApps script; +http://script.google.com/bot.html)"
Run Code Online (Sandbox Code Playgroud)

而且一直是同一个IP。而现在仍然如此,

这种爬行模式常见吗?

googlebot web-crawler google-apps-script

1
推荐指数
1
解决办法
3457
查看次数

迭代向量字符串的字符(C++禁止指针和整数之间的比较)

我试图迭代一个字符串向量,并在字符串的每个字符上:

但我得到一个错误:C++禁止指针和整数之间的比较.

In member function ‘int LetterStrings::sum(std::vector<std::basic_string<char> >)’:

error: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
Run Code Online (Sandbox Code Playgroud)

以下是我的代码:

#include<iostream>
#include<vector>
#include<typeinfo>
#include<string>

using namespace std;

class LetterStrings {
    public:
        int sum(vector <string> s) {
            int i, j = 0;
            int count = 0;
            for(i=0;i<s.size();i++) {
                for(j=0;j<s[i].length();j++) {
                    if(s[i][j] != "-") {
                        count ++;
                    }
                }
            }
            return count;
        }
};
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我,我的代码有什么问题.

**我对C++很陌生.

c++

0
推荐指数
1
解决办法
404
查看次数

尝试保存模型Django 1.5时出现`namedtuple_as_object`错误

我试图更新int我的Django模型中的一个字段.

但是在更新此字段时出现以下错误.

(这是python manage.py shell在ipython中使用)

# this is what I m trying to do
>> a = download.objects.get(id=1)
>> a.url = ""
>> a.save() # raises an error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 a.save()

/usr/local/lib/python2.7/dist-packages/django/db/models/base.pyc in save(self, force_insert, force_update, using, update_fields)
    544 
    545         self.save_base(using=using, force_insert=force_insert,
--> 546                        force_update=force_update, update_fields=update_fields)
    547     save.alters_data = True
    548 

/usr/local/lib/python2.7/dist-packages/django/db/models/base.pyc in save_base(self, raw, cls, origin, force_insert, force_update, using, update_fields)
    624                         values = …
Run Code Online (Sandbox Code Playgroud)

python django django-models

0
推荐指数
1
解决办法
2049
查看次数