Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending data to php page
#1
Hi,

I'm trying to send data to a PHP page, but I get the error

Quote:TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

I appreciate any help on this.

import urllib.request
#import urllib
from urllib.parse import urlencode, quote_plus

apiKeyValue = "xxxx"
board = 2
temp = 12.22
humidity = 33

mydata=[('apiKeyValue','xxxx'),('board','2'), ('temp','22.22'), ('humidity','15')]    #The first is the var name the second is the value
result = urlencode(mydata, quote_via=quote_plus)

path='http://mtpage/post_dht_data.php' 
req=urllib.request.Request(path, result)
#print(req)

req.add_header("Content-type", "application/x-www-form-urlencoded")
page=urllib.request.urlopen(req).read()
print(page)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  trying to save data automatically from this page thunderspeed 1 2,018 Sep-19-2021, 04:57 AM
Last Post: ndc85430
  Scraping a page with log in data (security, proxies) iamaghost 0 2,147 Mar-27-2021, 02:56 PM
Last Post: iamaghost
  Sending data from a websocket client to another server lemon 1 3,601 May-25-2020, 02:26 PM
Last Post: lemon
  use Xpath in Python :: libxml2 for a page-to-page skip-setting apollo 2 3,637 Mar-19-2020, 06:13 PM
Last Post: apollo
  scrape data 1 go to next page scrape data 2 and so on alkaline3 6 5,188 Mar-13-2020, 07:59 PM
Last Post: alkaline3
  Scrap data from not standarized page? zarize 4 3,317 Nov-25-2019, 10:25 AM
Last Post: zarize
  Sending data post to wsgiref JohnnyCoffee 0 1,791 Oct-24-2019, 09:04 PM
Last Post: JohnnyCoffee
  Selenium get data from newly accessed page hoff1022 2 2,952 Oct-09-2019, 06:52 PM
Last Post: hoff1022
  Scraping data from ebay seller page yuvalta 3 6,003 Sep-25-2019, 04:22 AM
Last Post: sandramoraes
  [Python 3] - Extract specific data from a web page using lxml module Takeshio 9 7,150 Aug-25-2018, 08:46 AM
Last Post: leotrubach

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020