title: Unpacking a dictionary and passing to a function as keyword parameters
body: <p>I am trying in python to unpack some dict into some function:</p>
  
  <p>I have a function that get <code>packet</code> as parameter (that should be dict)</p>
  
  <pre><code>def queue(self, packet):
      self.topic.publish(self.message, self.client, **packet)
  </code></pre>
  
  <p>and I call it this way:</p>
  
  <pre><code>queue({
          'an_item': 1,
          'a_key': 'value'
      })
  </code></pre>
  
  <p>the publish function, is in <a href="https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/pubsub/google/cloud/pubsub/topic.py#L237" rel="nofollow noreferrer">3rd party api</a> (Google Pub/Sub API) and from what I looked at source:</p>
  
  <pre><code>def publish(self, message, client=None, **attrs):
      ...
      message_data = {'data': message, 'attributes': attrs}
      message_ids = api.topic_publish(self.full_name, [message_data])
  </code></pre>
  
  <p>it's accepting **attrs in order to pass all keyword parameters into another function.</p>
  
  <p>Currently.. my queue() function isn't working.</p>
  
  <p>How, if possible, can I fix my <code>queue()</code> function to unpack the <code>packet</code> dict argument into something <code>publish()</code> will accept?</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>Some error messages I got.</p>
  
  <p>for:</p>
  
  <pre><code>def queue(self, packet):
      self.topic.publish(self.message, self.client, **packet)
  </code></pre>
  
  <p>I get: <code>TypeError: 1 has type &lt;class 'int'&gt;, but expected one of: (&lt;class 'bytes'&gt;, &lt;class 'str'&gt;)</code></p>
  
  <hr>
  
  <p>for:</p>
  
  <pre><code>def queue(self, packet):
      self.topic.publish(self.message, self.client, packet)
  </code></pre>
  
  <p>I get: <code>publish() takes from 2 to 3 positional arguments but 4 were given</code></p>
  
  <hr>
  
  <p>for:</p>
  
  <pre><code>def queue(self, **packet):
      self.topic.publish(self.message, self.client, packet)
  </code></pre>
  
  <p>I get: <code>TypeError: queue() takes 1 positional argument but 2 were given</code></p>
  
  <hr>
  
  <p>and for:</p>
  
  <pre><code>def queue(self, *packet):
      self.topic.publish(self.message, self.client, packet)
  </code></pre>
  
  <p>I get: <code>TypeError: publish() takes from 2 to 3 positional arguments but 4 were given</code></p>
  
  <hr>
  
  <p>EDIT 2:</p>
  
  <p>as @gall suggested correctly, it is the data I was sending and there is no problem with the unpacking. with this function:</p>
  
  <pre><code>def queue(self, packet):
      self.topic.publish(self.message, self.client, **packet)
  </code></pre>
  
  <p>It works when I call it with strings only:</p>
  
  <pre><code>queue({
          'an_item': '1',
          'a_key': 'value'
      })
  </code></pre>
  
  <p>Thank you all!</p>