2015-02-05 68 views
0

我使用OAuthLib讓訪問者通過LinkedIn登錄我的網站。我現在想A股(更新)發佈到自己的個人資料(as described here),我嘗試使用下面的代碼來執行:`ValueError:需要多個值才能在Python OAuthLib中解壓縮?

xmlStr = '<share><comment>This is a comment.</comment><content><title>This is the title</title><description>This is the description</description><submitted-url>http://www.isittuesday.co.uk</submitted-url><submitted-image-url>http://stunningplaces.net/wp-content/uploads/2014/05/11-Rio-de-Janeiro-Cochabana-Beach.-Photo-by-ballnkicka.com_.jpg</submitted-image-url></content><visibility><code>connections-only</code></visibility></share>' 
r = linkedInApp.post('people/~/shares', data=xmlStr, headers={'content-type': 'application/xml'}) 

不幸的是,這讓我在第二行的錯誤,說ValueError: need more than 1 value to unpack(回溯在消息下面)。

有誰知道最新錯了嗎?歡迎所有提示!

Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app 
    response = self.make_response(self.handle_exception(e)) 
    File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception 
    reraise(exc_type, exc_value, tb) 
    File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app 
    response = self.full_dispatch_request() 
    File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request 
    rv = self.handle_user_exception(e) 
    File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception 
    reraise(exc_type, exc_value, tb) 
    File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request 
    rv = self.dispatch_request() 
    File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request 
    return self.view_functions[rule.endpoint](**req.view_args) 
    File "/Users/kramer65/repos/v/app/views.py", line 694, in authorized 
    r = linkedInApp.post('people/~/shares', data=xmlStr, headers={'content-type': 'application/xml'}) 
    File "/Library/Python/2.7/site-packages/flask_oauthlib/client.py", line 371, in post 
    return self.request(*args, **kwargs) 
    File "/Library/Python/2.7/site-packages/flask_oauthlib/client.py", line 424, in request 
    data, content_type = encode_request_data(data, format) 
    File "/Library/Python/2.7/site-packages/flask_oauthlib/client.py", line 154, in encode_request_data 
    return url_encode(data or {}), 'application/x-www-form-urlencoded' 
    File "/Library/Python/2.7/site-packages/werkzeug/urls.py", line 729, in url_encode 
    return separator.join(_url_encode_impl(obj, charset, encode_keys, sort, key)) 
    File "/Library/Python/2.7/site-packages/werkzeug/urls.py", line 308, in _url_encode_impl 
    for key, value in iterable: 
ValueError: need more than 1 value to unpack 

回答

1

有一個在flask_oauthlib.client模塊怪異的行爲,如果你調用​​方法沒有content_type參數,它url_encode的數據。由於你的data參數(xmlStr)是純字符串,你會得到異常。

底線,你的電話更改爲以下,一切都應該是好:

r = linkedInApp.post('people/~/shares', data=xmlStr, content_type='application/xml') 
+0

感謝在清除了。我的代碼不會產生錯誤了。不幸的是,我現在仍然從linkedin上得到一個錯誤,說''urorcode':0,u'status':400,u'message':u'Couldn ' t解析Json body:意外字符(' < '(code 60)):期望一個有效值(數字,字符串,數組,對象,'真','假'或' null ')\ n at [Source:[email protected]; line:1,column:2]',u'requestId':u'L1E2VPMYB7',u'timestamp':1423157990816}'。任何想法? – kramer65 2015-02-05 17:42:01

+0

它期望你給他們發送JSON正文。 – 2015-02-05 17:43:57

+0

在文檔(https://developer.linkedin.com/documents/share-api)中,他們用XML來舉例說明。我也嘗試插入一個字典(並刪除co​​ntent_type),但是這給了我:'u'errorCode':0,u'status':400,u'message':u'Can不能解析JSON共享文檔。 nRequest正文:\ n \ n錯誤:\ nnull',u'requestId':u'V34TY5BRAC',u'timestamp':1423158376420}'。任何想法? – kramer65 2015-02-05 17:46:59

相關問題