Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python and the new way to add data to urllib requests

I'm getting the error,

AttributeError: 'Request' object has no attribute 'add_data'

from a library that uses urllib.request

In Python 2.7-3.3 urllib.request contained a add_data() method.

But In Python 3.4 the documentation states that,

Changed in version 3.4: The request methods add_data, has_data, get_data, get_type, get_host, get_selector, get_origin_req_host and is_unverifiable that were deprecated since 3.3 have been removed.

How do I add data to urllib requests in Python3.4?

like image 854
AlexLordThorsen Avatar asked Sep 08 '14 22:09

AlexLordThorsen


1 Answers

Just assign to the data attribute for urllib.request.

 request.data = "Some data"
like image 114
AlexLordThorsen Avatar answered Sep 28 '22 03:09

AlexLordThorsen