decoding

Swift Decode [String: Any]

主宰稳场 提交于 2020-08-03 06:01:09
问题 So I have this API that returns a dictionary of [String: Any] , I know that what comes as Any is Decodable or an array of Decodable however I can't for the life of me figure out how to take that dictionary and decode it to some struct: What I have goes basically like this: public func call<T: Codable> (completion handler: @escaping (T?) -> ()) { let promise = api.getPromise () promise.done (on: DispatchQueue.main, { (results: [String:Any]) let decodedResults:T? = results.decode (as: T.self) /

FFmpeg - avcodec_receive_frame returns AVERROR(EAGAIN)

馋奶兔 提交于 2020-07-18 08:14:34
问题 I'm using an QOpenGL widget to draw frames. However, I'm struggling to get frames by using avcodec_receive_frame . It ended within the block else if (ret == AVERROR(EAGAIN)) and returned -11. I have no idea what made this happen. Also I checked that codecs were fine, so I guess the problem wasn't caused by codecs. MyDemux.cpp AVPacket* MyDemux::allocatePacket() { AVPacket* packet = av_packet_alloc(); return packet; } AVFrame* MyDemux::allocateFrame() { AVFrame* frame = av_frame_alloc();

Encoding issue : decode Quoted-Printable string in Python

别说谁变了你拦得住时间么 提交于 2020-07-03 03:24:08
问题 In Python, I got a string encoded in Quoted-Printable encoding mystring="=AC=E9" This string should be printed as é So I want to decode it and encode it in UTF-8, I guess. I understand that something is possible through import quopri quopri.decodestring('=A3=E9') But then, I'm completely lost. How would you do decode/encode this string to get printed properly? 回答1: import quopri Encoding: You can encode the character 'é' to Quoted-Printable using quopri.encodestring(). It takes a bytes object

Error in json.loads() for data that has base64 decoding applied

无人久伴 提交于 2020-06-27 04:27:11
问题 I am trying to use json.loads() in python I get the error: the JSON object must be str, not 'bytes' a = {'h': '123', 'w': '12345', 'data': "b'eyJod2lkIjpwomfcwpvepovnepovqrepniLLKJAMSNDMSNDMAWEFMOEDAad='"} a.update(json.loads(base64.b64decode(a['data']))) Here the 'data' portion of a was being loaded in as a json dump with b64encoding. 'data':base64.b64encode(json.dumps(test).encode()); where test = some string eg('epovqrepniLLKJAMSNDMSNDMAWEFMOEDAad=') I have tried using: a.update(json.loads

Error in json.loads() for data that has base64 decoding applied

末鹿安然 提交于 2020-06-27 04:27:00
问题 I am trying to use json.loads() in python I get the error: the JSON object must be str, not 'bytes' a = {'h': '123', 'w': '12345', 'data': "b'eyJod2lkIjpwomfcwpvepovnepovqrepniLLKJAMSNDMSNDMAWEFMOEDAad='"} a.update(json.loads(base64.b64decode(a['data']))) Here the 'data' portion of a was being loaded in as a json dump with b64encoding. 'data':base64.b64encode(json.dumps(test).encode()); where test = some string eg('epovqrepniLLKJAMSNDMSNDMAWEFMOEDAad=') I have tried using: a.update(json.loads

Decoding/parsing CSV and CSV-like files in Swift

时光怂恿深爱的人放手 提交于 2020-06-01 07:38:07
问题 I'll have to write a very customised CSV-like parser/decoder. I have looked for open source ones on Github, but not found any that fits my needs. I can solve this, but my question is if it would be a total violation of the key/value decoding, to implement this as a TopLevelDecoder in Swift. I have keys, but not exactly key/value pairs. In CSV files, there is rather a key for each column of data, There are a number of problem with the files I need to parse: Commas are not only for separation

scraping chinese characters python

血红的双手。 提交于 2020-05-14 10:18:20
问题 I learnt how to scrap website from https://automatetheboringstuff.com. I wanted to scrap http://www.piaotian.net/html/3/3028/1473227.html in which the contents is in chinese and write its contents into a .txt file. However, the .txt file contains random symbols which I assume is a encoding/decoding problem. I've read this thread "how to decode and encode web page with python?" and figured the encoding method for my site is "gb2312" and "windows-1252". I tried decoding in those two encoding

Base 64 decoding in Python and Oracle

江枫思渺然 提交于 2020-03-25 12:34:04
问题 I am trying to replicate some python 2.7 code in Oracle database. When trying to replicate base64 decoding , I am getting different output. Python Code: # -*- coding: utf-8 -*- import base64 print(base64.b64decode('rO0ABXVyAAJbQqzzF/gGCFTgAgAAeHAAAAAgGLCRnyhEZhzJJRd7EoVPp2XWTRgDNYHq4cAghvXvTaw=')) Python Code Output: �� ur [B���T� xp ���(Df�%{�O�e�M5���� ���M� Oracle Query: select utl_raw.cast_to_varchar2(UTL_ENCODE.BASE64_DECODE( UTL_RAW.CAST_TO_RAW ('rO0ABXVyAAJbQqzzF

Decoding Base64 pdf giving broken file

有些话、适合烂在心里 提交于 2020-02-02 11:15:13
问题 Can someone please explain why decoding Base64 giving a broken pdf? I need to find the way how to decode Base64 and get pdf out. When i use this service https://emn178.github.io/online-tools/base64_decode_file.html I am able to pass Base64 and get file out without problem. But when i do same in node.js I am getting empty (broken) file consistently. I tried different packages like: js-base64, atob and none of them worked, getting same empty file as the result. Link to my code: https://repl.it/

Bittrex websockets encoding method?

微笑、不失礼 提交于 2020-01-25 07:25:13
问题 It´s not a big deal to mimic the websocket connection made to bittrex from www, using chromes dev tools: GET https://socket.bittrex.com/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22c2%22%7D%5D&_=1524596108843 This return a token "ConnectionToken":"gbLsm8C6Jck1mQTTFjmuIv5qgUuMZz/kXU1s+fAnjnW qUFQocNBfp3VOrd/y0acxWL5Fv7MZ54heRddLYZS+EMhLnaPPQiSZblvgJPCbLKqZTIkb" That needs to be used with: wss://socket.bittrex.com/signalr/connect? transport=webSockets&clientProtocol